Color scheme

currentColor Patterns

When you build a component, the text color, border color, icon fill, and shadow tint often need to match. Without currentColor, you end up repeating the same value (or the same custom property) across every property that accepts a color. Change the value in one place and forget another, and the component drifts out of sync. The currentColor keyword solves this by acting as a built-in variable that always resolves to the element's computed color property. Set the text color once, and every property that uses currentColor follows automatically.

This keyword has been in CSS since before custom properties existed. It has universal browser support and costs nothing to use. Understanding where it shines, where it has gotchas, and how it interacts with the token system you built this unit will make your components leaner and easier to maintain.

How currentColor Works

Every element in the DOM has a computed value for the color property, whether it is set explicitly or inherited from a parent. The currentColor keyword resolves to that computed value wherever a <color> is accepted. It works in borders, box shadows, text shadows, outlines, backgrounds, gradients, SVG fill and stroke, and even inside color-mix() or relative color syntax.


        .alert {
            color: #b91c1c;
            border: 2px solid currentColor;
            box-shadow: 0 2px 8px currentColor;
        }
    

The border and shadow are both #b91c1c without repeating the value. Change the color to any other value and everything updates together.

Implicit Defaults

Several CSS properties already default to currentColor when you omit a color value. border-color, outline-color, and text-decoration-color all inherit from color by default. Writing border: 2px solid without a color gives you the same result as border: 2px solid currentColor. The keyword becomes essential when you need to be explicit (for readability or to pass it into a function) or when the property does not default to it (like box-shadow, background-color, or SVG fill).

Three Components, One Color Input

The real value of currentColor shows up when you build components that need to work in multiple color contexts. Here are three small components that each synchronize several visual properties through a single color declaration.

A Status Badge

A badge that needs its text, border, and background tint to match. The background uses currentColor at low opacity through color-mix():


        .badge {
            color: var(--color-accent);
            border: 1px solid currentColor;
            background: color-mix(in srgb, currentColor 12%, transparent);
            padding: 0.2rem 0.8rem;
            border-radius: 9999px;
            font-size: 1.4rem;
            font-weight: 600;
        }

        .badge--success { color: #16a34a; }
        .badge--warning { color: #ca8a04; }
        .badge--danger  { color: #dc2626; }
    

Each variant only sets color. The border and background tint update automatically. Without currentColor, each variant would need three declarations instead of one.

A Button with an SVG Icon

Inline SVG icons are a natural fit for currentColor. Setting fill="currentColor" on the SVG path makes the icon match the surrounding text color, and both update together on hover:


        <button class="btn">
            <svg aria-hidden="true" viewBox="0 0 24 24" width="18" height="18">
                <path fill="currentColor" d="M12 4l8 8-8 8-1.4-1.4L16.2 13H4v-2h12.2l-5.6-5.6z" />
            </svg>
            Continue
        </button>
    

        .btn {
            color: var(--color-accent);
            border: 1px solid currentColor;
            background: transparent;
            display: inline-flex;
            align-items: center;
            gap: 0.6rem;
            padding: 0.6rem 1.2rem;
            border-radius: var(--radius-md);
            cursor: pointer;
            transition: color 0.2s, background-color 0.2s;
        }

        .btn:hover {
            color: #ffffff;
            background-color: var(--color-accent);
        }
    

On hover, the text turns white and the icon follows. The border also flips to white because it is still tracking currentColor. The entire color shift happens by changing one property.

A Blockquote with a Colored Left Border and Shadow

A styled blockquote where the left border, the subtle shadow, and the quotation mark icon all share one color:


        .pullquote {
            color: var(--color-accent);
            border-left: 4px solid currentColor;
            box-shadow: -4px 0 12px currentColor;
            padding: 1.2rem 1.6rem;
            font-style: italic;
        }

        .pullquote p {
            color: var(--color-text);
        }
    

Notice the inner <p> resets its color to the normal text color. The border and shadow stay locked to the accent because they are set on the outer element where color is still the accent. This is an important pattern: set color on the wrapper for the decorative properties, then override color on the text content inside.

Inheritance Gotchas

currentColor is powerful, but it follows the cascade, and that can produce surprises if you are not careful about where color is set.

The Order-of-Resolution Trap

When color and a property using currentColor are set on the same element, the final computed value of color wins for everything. This can be counterintuitive:


        .box {
            color: red;
            border: 2px solid currentColor;
            box-shadow: 0 0 5px currentColor;
            color: black;
        }
    

You might expect the border to be red because it was declared after color: red. But CSS does not resolve properties line by line. All declarations are collected first, then the final computed color (black) is used. The border and shadow are both black. This is not a bug. It is how the cascade works, but it catches people who think of CSS as procedural.

Child Inheritance Overrides

Because color is an inherited property, any child that sets its own color will change what currentColor resolves to for that subtree. This is usually what you want (the blockquote pattern above relies on it), but it can cause problems when a child's color unintentionally affects decorative properties:


        .card {
            color: var(--color-accent);
            border: 1px solid currentColor;
        }

        /* A child link inside the card */
        .card a {
            color: var(--color-link);
        }

        /* The link's underline is now --color-link, not --color-accent */
    

If the link has a default text-decoration-color (which inherits from color), its underline color comes from --color-link, not --color-accent. This is correct behavior, but you need to be aware of it when designing components. The rule of thumb is: set color at the level where you want currentColor to resolve, and override it only on descendants where you want a different value.

currentColor in Custom Properties

You can store currentColor in a custom property, but be aware that it resolves at the point of use, not at the point of declaration:


        :root {
            --border-tint: currentColor;
        }

        .header {
            color: navy;
            border: 1px solid var(--border-tint); /* navy */
        }

        .footer {
            color: gray;
            border: 1px solid var(--border-tint); /* gray */
        }
    

The custom property does not capture a color value. It stores the keyword currentColor literally, and each element resolves it against its own computed color. This is useful but can be confusing if you expect the variable to hold a fixed value.

currentColor vs. Custom Properties

With a full token system in place, you might wonder whether currentColor is still necessary. The answer is that they solve different problems and work well together.

Custom properties name a specific value. --color-accent is always your accent color regardless of context. currentColor is contextual. It means "whatever the text color is right here." When you want a border to always be the accent color, use the custom property. When you want a border to match the text color of whatever context the component appears in, use currentColor.

The badge example above could use var(--color-accent) for the border and background, but then each color variant would need three overrides instead of one. currentColor reduces those three overrides to a single color change. The fewer properties you repeat in variants, the easier the component is to maintain and the less likely it is that values drift out of sync.

Live Demo

These three components all use currentColor for their borders, shadows, and icon fills. Change the color with the selector below and watch every decorative property update from a single color value. Use the theme toggle to see how the demo responds in both light and dark mode:

Color scheme
Badge Status Active
Button + Icon
Blockquote

One color input drives every decorative property.

Resources

Teaching Video Checklist

When you record your teaching video, make sure your teammates come away understanding these concepts:

  • What currentColor is and how it resolves to the element's computed color property
  • Which properties already default to currentColor when you omit a color (borders, outlines, text-decoration) and which require you to write it explicitly (box-shadow, background, SVG fill)
  • How to use it in at least two of the three patterns: borders, SVG icon fills, and shadows or background tints
  • The order-of-resolution gotcha: when color is set twice on the same element, the final value wins for all properties using currentColor
  • When to reach for currentColor vs. a custom property: contextual color matching vs. a specific named value

Show a live demo in your video. Build a small component (a badge, a button with an SVG icon, or a styled blockquote) that uses currentColor for at least two decorative properties. Then create two or three color variants by only changing the color property, and show your teammates how the entire component updates. Compare the token count before and after: how many color declarations did you eliminate?