# @starting-style

> The `@starting-style` CSS directive defines the initial styles of an element before its first style update.

## How do I animate an element when it first appears with CSS?

The directive that sets the starting values of properties for an element that has just been added to the page or changed from 'display: none'. Allows animating the appearance of elements like dialogs and popovers with plain transitions.

- Topic: Directives
- Type: directive
- Browser support: Chrome 117+, Chrome Android 117+, Edge 117+, Firefox 129+, Firefox Android 129+, Safari 17.5+, Safari iOS 17.5+

## Example

Wrong:

```css
@starting-style {
  dialog[open] { opacity: 0; }
}
dialog[open] {
  opacity: 1;
  transition: opacity 0.3s;
}
```

Right:

```css
dialog[open] {
  opacity: 1;
  transition: opacity 0.3s;
}
@starting-style {
  dialog[open] { opacity: 0; }
}
```

`@starting-style` has no extra specificity, so it must come after the normal rule or the normal rule overrides it.

## Common mistakes

- Writing `@starting-style` before the normal rule, so the normal rule overrides it.
- The exit animation is cut off because `display` isn't transitioned with 'allow-discrete'.

## Key points

- `@starting-style` holds the before-open values, while the normal rule holds the open state.
- Elements shown from `display: none` transition `display` with `transition-behavior: allow-discrete`.
- Top-layer elements like dialogs and popovers also transition `overlay` with 'allow-discrete'.
- Motion is removed or reduced inside `@media (prefers-reduced-motion: reduce)`.

## Interview questions

### Why do I need @starting-style for transitions?

Transitions only run when a value changes. A newly shown element has no previous style, so `@starting-style` provides one.

### Does @starting-style work with keyframe animations?

It is not needed for them. `@keyframes` animations already run when an element appears; `@starting-style` is for transitions.

### Can I nest @starting-style inside a rule?

Yes. Inside a rule, `@starting-style { opacity: 0; }` applies to the element the rule matches.

## Related cards

- [transition](https://wonderium.dev/css/transition.md)
- [:popover-open](https://wonderium.dev/css/popover-open.md)
- [`<dialog>`](https://wonderium.dev/html/dialog.md)
- [display](https://wonderium.dev/css/display.md)
- [::details-content](https://wonderium.dev/css/details-content.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/starting-style
- Last updated: 2026-11-25
