CSS transitions are great after an element already exists: change a class, hover an element, or update a custom property, and the browser interpolates the change. But the very first frame has always been awkward. If you set opacity: 0 in a normal rule and add a transition, some browsers may paint the element already hidden and then animate it; other cases simply render the final state with no entry animation at all.

@starting-style gives CSS a proper place to declare starting values for an element’s initial style update. It is especially useful for <dialog> popovers, elements entering the top layer, and page-entry motion where you do not want JavaScript to add a class after paint.
What problem does @starting-style solve?
Normally, a transition needs a before state and an after state. On first render, the browser only knows the element’s final computed style. This rule puts the before state in CSS:
@starting-style {
.card {
opacity: 0;
transform: translateY(16px);
}
}
.card {
opacity: 1;
transform: none;
transition:
opacity .5s ease,
transform .5s ease;
}
The element is not normally styled as hidden. It starts hidden only for its first style resolution and animates to its real style. That distinction matters for accessibility and unsupported browsers.

Support matrix and feature detection
Current support, based on the available version data, is:
- Chrome 117+ and Edge 117+
- Firefox 129+
- Safari 17.5+
Release timing can differ by channel and operating system, so check Can I use before making motion a hard dependency.
Use @supports so older browsers receive the final visible style:
.card {
opacity: 1;
transform: none;
}
@supports (transition-behavior: allow-discrete) {
@starting-style {
.card {
opacity: 0;
transform: translateY(16px);
}
}
.card {
transition: opacity .5s ease, transform .5s ease;
}
}
Do not put opacity: 0 in an unconditional base rule. If @starting-style is ignored, that can leave content permanently invisible.
Important rules: display, overlay, top layer, and backdrop
Animating a modal dialog is not the same as animating an ordinary card. display and overlay are discrete properties. They cannot smoothly interpolate, and they need explicit handling for entry and exit animations.
- Use
transition-behavior: allow-discretewhen transitioningdisplayoroverlay. - Include both properties in the transition list;
overlaykeeps the element in the top layer long enough to play its exit animation. - For closing animations, add the starting value inside the hidden state using
@starting-style; discrete values flip at 0% when entering and at 100% when exiting. - Style
::backdropseparately. It also needs starting values and a transition. - Top-layer behavior applies to native modal dialogs and popovers; manually positioned fixed elements do not automatically get it.
Minimal runnable dialog demo
HTML
<button id="open">Open dialog</button>
<dialog id="box">
<h2>Hello</h2>
<p>This dialog animates in and out without a JavaScript animation class.</p>
<form method="dialog">
<button>Close</button>
</form>
</dialog>
CSS
dialog {
border: 0;
border-radius: 14px;
padding: 24px;
opacity: 1;
transform: scale(1);
transition:
opacity .22s ease,
transform .22s ease,
overlay .22s ease allow-discrete,
display .22s ease allow-discrete;
}
@starting-style {
dialog[open] {
opacity: 0;
transform: scale(.94);
}
dialog[open]::backdrop {
opacity: 0;
}
}
dialog::backdrop {
background: rgb(0 0 0 / .45);
opacity: 1;
transition: opacity .22s ease;
}
/* Exit state */
dialog:not([open]) {
opacity: 0;
transform: scale(.94);
@starting-style {
opacity: 1;
transform: scale(1);
}
}
Effect: the dialog fades and scales in; the backdrop fades with it. On close, overlay .22s allow-discrete prevents the browser from removing the dialog before the exit transition finishes.
JavaScript
const box = document.querySelector('#box');
document.querySelector('#open').addEventListener('click', () => box.showModal());
Fallback
Without support, call showModal() and close() normally. The dialog appears immediately in its final visible state. If you need the animation everywhere, add a class-based dialog polyfill pattern or a small JavaScript entrance/exit state machine.
Theme switching: do not confuse the two mechanisms
@starting-style does not animate a global theme change for elements already on the page. It only defines values for first render. For an existing button, card, or navigation bar, an ordinary transition handles color changes:
:root {
color-scheme: light;
--bg: #fff;
--text: #161616;
}
:root[data-theme="dark"] {
color-scheme: dark;
--bg: #161616;
--text: #f4f4f5;
}
body {
background: var(--bg);
color: var(--text);
transition: background-color .3s ease, color .3s ease;
}
HTML and JavaScript
<button id="theme">Toggle theme</button>
<script>
const root = document.documentElement;
document.querySelector('#theme').addEventListener('click', () => {
const next = root.dataset.theme === 'dark' ? 'light' : 'dark';
root.dataset.theme = next;
});
</script>
Effect: existing elements smoothly change colors. @starting-style is unnecessary here. If you want a crossfade, circular reveal, or screenshot-like transition across the whole page, use the View Transitions API and feature-detect document.startViewTransition. Otherwise, limit your transition to a specific component.
Fallback
Older browsers simply swap CSS variables instantly. Keep contrast and focus states correct in both themes; the animation is enhancement, not the state itself.
Complete page entrance animation
This example staggers the header, hero text, and cards on initial page load without adding classes after DOMContentLoaded.
HTML
<main class="page">
<header class="hero">
<p class="eyebrow">CSS Tutorial</p>
<h1>Animate the first render</h1>
<p class="lead">Use starting styles for motion that does not depend on JavaScript.</p>
</header>
<section class="grid">
<article class="card">Dialog</article>
<article class="card">Theme</article>
<article class="card">Page load</article>
</section>
</main>
CSS
.hero,
.card {
opacity: 1;
transform: none;
}
@supports (transition-behavior: allow-discrete) {
.hero,
.card {
transition:
opacity .6s ease,
transform .6s cubic-bezier(.2,.7,.2,1);
}
.card:nth-child(2) { transition-delay: .08s; }
.card:nth-child(3) { transition-delay: .16s; }
@starting-style {
.hero,
.card {
opacity: 0;
transform: translateY(20px);
}
}
}
@media (prefers-reduced-motion: reduce) {
.hero,
.card {
transition: none;
}
}
JavaScript
// None required for the entrance animation.
// Put progressive-enhancement code here, such as saving user preferences.
Effect: the hero rises and fades in, followed by each card. The delay creates a stagger, while the final CSS rules keep the content readable and in normal document flow.
Fallback
Browsers without support ignore the starting block and show all content immediately. The base rule uses opacity: 1, so the page never depends on animation support to be visible.
Common mistakes
- Hiding content in a normal rule. Writing
.card { opacity: 0; }outside@starting-stylecan make content invisible when the feature is unsupported. - Forgetting the transition. A starting value without
transitionusually snaps directly to the final value. - Animating discrete properties incorrectly. Add
allow-discretefordisplayandoverlay; they will not tween like opacity. - Expecting exit animations without
overlay. A dialog or popover can leave the top layer immediately, cutting off the animation. - Relying on nested
@starting-styleeverywhere. Nested rules are convenient, but check your browser targets and your CSS minifier; the block form is safer for broad support. - Using it for theme changes. Existing elements transition from their current computed values. Use normal transitions for color changes and View Transitions for global page-level effects.
- Ignoring reduced motion. Entrance animation should respect
prefers-reduced-motion, especially for large or repeated motion.
When to reach for it
Use @starting-style when the animation belongs to an element’s first appearance: page sections, newly rendered components, native dialogs, and popovers. Keep final styles visible by default, feature-detect the tricky discrete cases, and reserve View Transitions for coordinated full-page theme or route changes. With those boundaries clear, you can remove a surprising amount of requestAnimationFrame and class-toggling JavaScript from your UI code.