What I’d ship now from CSS alpha() and dialog updates

You scroll the description inside a quick view dialog on a store and the product page behind it moves. Or you click the dimmed area around a modal and it stays open, because the only exit is a small X some plugin put in the corner. Both behaviors have CSS answers now, and they showed up in the same weekly roundup as a color function I’ve been waiting for. The post is What’s !important #13 on CSS-Tricks, and the pieces I keep returning to are the CSS alpha() function, the closedby attribute on <dialog>, and native @function.

Where the CSS alpha() function fits in a theme palette

If you build WordPress themes you’ve already made this choice, probably without naming it. You can store raw channel values in a custom property and wrap them in a color function at every use, or you can store the finished color and pay for it the first time you need it translucent. The CSS-Tricks author walks through both, and the verdict there matches mine: option one is monotonous, option two makes the relative color syntax line long and noisy.

/* A: channels only, every use names a function */
--brand: 0.65 0.23 230;
color: oklch(var(--brand) / 0.5);

/* B: full color, alpha() only when needed */
--brand: oklch(0.65 0.23 230);
color: alpha(from var(--brand) / 0.5);

/* C: precomputed variant, works everywhere */
--brand: oklch(0.65 0.23 230);
--brand-soft: oklch(from var(--brand) l c h / 0.5);
color: var(--brand-soft);

The relative color syntax itself is fine, and MDN’s guide on relative colors is worth a read for how the origin color gets converted and taken apart into channels. But oklch(from var(–brand) l c h / 0.5) has two problems when it’s scattered across a theme. It hard-codes the color space into every declaration that wants transparency, so a palette move from oklch to lab touches all of them. And it’s long enough that people copy it without reading it. alpha(from var(–brand) / 0.5) fixes both, and the source makes the better argument: the format is irrelevant here, so naming it was noise.

Support is why I’m not shipping it on client work this month. Can I use has alpha() starting at Chrome 152, Firefox 155 and Safari 27, and at the time of that roundup the support was days old. A declaration the browser can’t parse gets dropped, and a dropped background on a checkout button is a real support ticket. So pattern C is still what I’d put in a storefront: compute the variant once and use var() everywhere. WordPress pushes you there anyway, since a theme.json palette comes out as –wp–preset–color-* custom properties, and that’s a fine place to generate tints. For a plugin admin UI or an internal tool where I set the browser floor myself, pattern B is the nicer authoring experience.

That leaves pattern C for public traffic, pattern B for anything I control end to end, and pattern A nowhere. Raw channels lost their only advantage this week.

What closedby changes about dialogs

The same roundup pulls in Una Kravets’ notes on <dialog>, and the scroll symptom comes first. When a modal is open and you scroll past the end of its content, the scroll chains through to the page behind it. That’s the thing from the top of this post, and overscroll-behavior: contain on the dialog ends it. It’s been around long enough that I treat it as a default now.

Dismissal is the bigger change. closedby takes three values, per MDN’s closedBy reference: any gives you light dismiss, so clicking the backdrop closes the dialog along with the Esc key. closerequest means Esc and platform close requests, but not backdrop clicks. none means only your own close mechanism works. Leave the attribute off entirely and a modal opened with showModal() behaves as closerequest while one opened with show() behaves as none. That’s the default every dialog you’ve already written is riding on.

Safari is the holdout. The source notes closedby isn’t supported there yet, so on a store with meaningful iOS traffic, attribute-only light dismiss won’t reach everyone. The backdrop click listener you already ship stays around for now. There’s a polyfill on npm if you want the behavior everywhere before Safari catches up.

Two smaller items from that same thread are worth stealing. scrollbar-gutter: stable stops the page shifting when the dialog opens and the page scrollbar disappears. Clients report that one-pixel jump as the site moving. The animation half, the @starting-style dance, is the part I re-google each time. I went through which of those animation properties I’d actually ship in an earlier post, so I won’t repeat it here.

For a quick view or a cart drawer, a few CSS lines now replace a chunk of the JS that plugins ship for the same job. For anything sitting over a checkout form I’d set closedby=”none”, because a stray click on the backdrop would throw away a half-filled form.

@function: three ways to make the same variants

The third piece is native @function, which the source expects to be the biggest CSS feature to reach Baseline this year. I wrote about how it differs from the Sass you know already, so this stays short: a Sass function runs at build time on values you knew when you compiled, and @function is evaluated in the browser at use time. That lines up with runtime custom properties in a way a compiler can’t, and it’s the situation a block theme creates when an admin picks the accent color in the site editor. I’m not sure how much of that flexibility survives the fine print on argument types, so verify before you build a system on it.

The pick depends on the project. In a classic theme with a build step and a fixed palette, keep the Sass and don’t churn a working setup. For a block theme where the palette can change from the editor, variants get generated in PHP or precomputed in theme.json today, and @function is the answer once support settles. A plugin with no build step at all is where @function earns its keep, because the alternatives are shipping a compiler or writing every variant by hand.

WordPress generates a lot of theme CSS in PHP, both the global styles inline block and the palette. @function only helps the CSS you author by hand, so the more block-editor-driven the site, the smaller its slice of the work gets.

The open question I’m left with is timing. Relative color syntax reads any origin color format, so once support catches up, alpha(from var(–wp–preset–color–primary) / 0.5) should work even when that color was picked in the editor and saved as hex. That’s the moment a chunk of PHP palette code stops being necessary. I honestly don’t know when I’d delete it, because every store I maintain has its own browser floor and none of them is mine to lower on my own. If you’re making the same call on a theme, or you want a read on whether the dialog fixes are worth doing before your next redesign, that’s the kind of work I do, and I’m happy to take a look.

author avatar
Ahmad Wael
I'm a WordPress and WooCommerce developer with 15+ years of experience building custom e-commerce solutions and plugins. I specialize in PHP development, following WordPress coding standards to deliver clean, maintainable code. Currently, I'm exploring AI and e-commerce by building multi-agent systems and SaaS products that integrate technologies like Google Gemini API with WordPress platforms, approaching every project with a commitment to performance, security, and exceptional user experience.

Leave a Comment