Leverage the CSS keyword "currentColor" to ensure a SVG stroke inherits the Font Color

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet

The CSS keyword currentColor allows you to set the color of all sorts of CSS properties like background-color, border-color, stroke, fill to the current font color. In this lesson we demonstrate this setting the stroke of an SVG to currentColor.

currentColor is well supported by all browser vendors. Even IE9 has it as you can see here: https://caniuse.com/#feat=currentcolor

Instructor: [00:00] Here, you can see paragraph of an SVG icon inside. If we take a closer look, we can see that the SVG icon color doesn't match up with the font color. We can easily fix this by applying another color to the CSS property stroke of the SVG. Let me quickly change it through it to demonstrate it.

[00:23] While this looks well here, sometimes, you might do something different and just want to use the current font color. Luckily, this is possible using the CSS keyword current color. Voila! We see the colors now match up.

[00:40] Now we can change the color of our text. As you will see, the SVG icon stroke will always match up with the font color. This comes in handy, especially if you make reusable components using a JavaScript UI library.

[00:56] One more thing to know, you can use the current color for every CSS property accepting a color.