1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

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

    Nik GrafNik Graf
    cssCSS

    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

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 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.

    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.

    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.

    One more thing to know, you can use the current color for every CSS property accepting a color.