New series: what assistive tech really hears on your checkout page. Start with part one →
Shipwright
Home
CSS Jul 27, 2026 2 min read 213 views

Custom Properties as an API for Your Components

Mara Okafor

Mara Okafor

@maraokafor

Share

Expose a few well-named variables and keep the rest of your CSS private. Most CSS problems we see in reviews are not about a missing property. They are about a layout that was never told what it should do when the content changes size, and that is what this piece sets out to fix.

Cover illustration for the article Custom Properties as an API for Your Components
Figure 1. Expose a few well-named variables and keep the rest of your CSS private.

Start from the constraint

Begin by writing down the smallest and largest sizes the component must survive. Once those two numbers exist, properties such as clamp(), minmax(), and fit-content stop feeling like magic and start reading like a specification.

  • Set explicit minimum and maximum sizes first.
  • Prefer intrinsic sizing keywords over fixed pixel values.
  • Let the container decide, not the viewport.
  • Keep one fallback declaration above the modern one.

Where the layout bends

The tricky part is always the middle: the tablet widths nobody designs for, the translated label that is forty percent longer, the avatar that failed to load. Test those states on purpose by resizing the container rather than the whole window.

Simplicity is prerequisite for reliability.

Edsger W. Dijkstra, EWD498, 1975

Quick takeaway

Describe the extremes first and the in-between sizes mostly take care of themselves.

Browser support notes

📐

Intrinsic first

Let content size the box before you reach for fixed widths.

🧱

Grid for structure

Use grid for the page skeleton and flexbox inside components.

🎛️

Tokens for scale

Keep spacing and type steps in custom properties.

Everything here works in the current versions of Chrome, Firefox, and Safari. Where a feature landed recently we note the version, and the fallback is usually a single line that older engines simply ignore.

None of this is new, and that is the point. The techniques that last are usually the boring ones that are documented well and supported by the platform itself.

Wrapping up

We will revisit this in six months with fresh numbers. If the results change, we will update the post and note what changed at the end.

Mara Okafor

Mara Okafor

Author

Staff frontend engineer focused on CSS architecture and accessibility. Mara has audited more design systems than she can count and still gets excited about a good focus ring.

Related Posts

Comments 1

Ravi Shankar

Came for the snippet, stayed for the explanation.

Leave a comment

Your email will not be published. Sign in for a faster experience.

Supports **bold**, *italic*, and `code`.