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
Published 5 years ago
Updated 4 years ago

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.

egghead
egghead
~ 50 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today