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

Learn

Permalink to "Learn"

CSS can apply presentation attributes to SVG elements similar to how CSS applies attributes to HTML.

However, only SVG presentation attributes can be applied to SVG through CSS.

In the following example, all elements using the class background will have a black fill.

CSS classes can be applied to SVG Elements like in the example below.

SVG can also be styled with CSS Custom Properties. This enables artists and designers to theme an SVG document with the same styles as its HTML counterpart.

Apply

Permalink to "Apply"

Add the following css template to repeat-pattern.js. It shouldn't affect repeat-pattern until the static styles property has been set.

This demo requires a theme that includes:

To accomplish this, create another CSS template with CSS custom properties representing the required theme.

Add the CSS templates to the repeat-pattern custom element.

Next, add the background class to the <rect> representing the background element in our pattern.

Finally add CSS custom properties to the styles in index.html to theme repeat-pattern.

After completing this section, you'll be ready to explore more advanced concepts in SVG and Lit.