Back
Blog Post|#engineering

Using the currentColor CSS Property with SVG

Alex Anderson
Alex AndersonMonday, September 26, 2022
Paint on a canvas

The currentColor property provides the current text color of the selected element. The CSS cascade makes it so the child’s text color matches the parents, but the currentColor property can be used for any other color property as well, like background or border colors.

.parent { color: red; } .child { border-color: currentColor; /* Also red */ }

This also includes properties on SVG elements on the page. Using currentColor as the fill or stroke color on a shape or path will have that element take on the text color of its parent. It even works with a CSS animation.

It’s important to remember that this only works if the SVG is rendered directly on the page - it won’t work if the SVG is loaded with an <img> tag.

Share this post

twitterfacebooklinkedin

Related Posts:

Interested in working with us?

Give us some details about your project, and our team will be in touch with how we can help.

Get in Touch