This section of the tutorial covers the basics of using SVG with Lit including how to:

Learn

Permalink to “Learn”

In pattern making, an element refers to the smallest piece of a pattern that cannot be derived from other parts of the pattern.

The element in this demo will be a single piece of text. We can create text in SVG and Lit with SVG templates as demonstrated below.

In Lit, an SVG template must be the child of an <svg> element. The <svg> element must be contained inside an HTML template. An implementation of these requirements is demonstrated by the following example.

Apply

Permalink to “Apply”

Create a function called createElement that generates a <text> element with configurable display text using a Lit SVG template. Add text-specfic styling attributes to the <text> element.

Call createElement in the render() function of a repeat-pattern component similar to the example below.

Finally, create a reactive property called chars so that text rendered can be configured by consumers of repeat-pattern.

After completing this section, you'll be ready to learn how to create reusable structures in SVG in the next chapter.