HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. Entry & Exit Transitions

CSS Animations & Transitions

Entry & Exit Transitions

Animate elements as they enter, leave, or move through the top layer with starting styles and discrete property transitions. It covers first-render transitions, discrete properties, popovers, dialogs, top-layer removal, and reduced-motion handling.

Entry and exit motion needs a defined rendered state; otherwise the browser has no pair of values to interpolate. Starting styles and discrete transitions supply the missing state without keeping hidden content permanently rendered.

Modern CSS can animate elements as they enter or leave even when display and top-layer participation change, provided the starting and discrete states are declared explicitly. This removes the need to keep an invisible element permanently rendered merely to obtain an opacity transition. This topic also connects with CSS Transitions and View Transitions.

Why ordinary transitions miss entry states

A transition needs an old value and a new value. Newly rendered elements and elements returning from display: none do not normally have a rendered starting state, so opacity or transform transitions appear to be skipped.

Define the first rendered state

@starting-style supplies the value used for the first style update. Place it after the rule with the visible state when both rules have equal specificity.

Example

css

.notice {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 200ms, transform 200ms;
}

@starting-style {
  .notice {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

Transition discrete properties

Properties such as display change discretely rather than through intermediate values. Use transition-behavior: allow-discrete so the browser can delay the discrete change while interpolated properties finish.

Example

css

[popover] {
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity 180ms,
    transform 180ms,
    display 180ms allow-discrete,
    overlay 180ms allow-discrete;
}

[popover]:popover-open {
  opacity: 1;
  transform: scale(1);
}

@starting-style {
  [popover]:popover-open {
    opacity: 0;
    transform: scale(0.96);
  }
}

Entry Transition Reference

SyntaxPurposeExample
@starting-styleDefines the first rendered style.@starting-style { .item { opacity: 0; } }
transition-behaviorAllows discrete properties to participate.transition-behavior: allow-discrete
:popover-openSelects an open popover.[popover]:popover-open
overlayDefers removal from the top layer.transition: overlay 180ms allow-discrete

Complete Example

Run the complete document below in the Try It editor. Resize the preview or interact with the controls where the example calls for it.

Complete runnable example

html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Entry & Exit Transitions example</title>
  <style>
    * { box-sizing: border-box; }
    body {
      margin: 0;
      padding: 2rem;
      font-family: system-ui, sans-serif;
      line-height: 1.5;
    }
    main { max-width: 70rem; margin-inline: auto; }
    article, section, aside, form, .card, .panel {
      padding: 1rem;
      border: 1px solid #cbd5e1;
      border-radius: 0.6rem;
    }

.notice {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 200ms, transform 200ms;
}

@starting-style {
  .notice {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

[popover] {
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity 180ms,
    transform 180ms,
    display 180ms allow-discrete,
    overlay 180ms allow-discrete;
}

[popover]:popover-open {
  opacity: 1;
  transform: scale(1);
}

@starting-style {
  [popover]:popover-open {
    opacity: 0;
    transform: scale(0.96);
  }
}
  </style>
</head>
<body>
  <main><button popovertarget="transition-demo">Open notice</button><div id="transition-demo" popover class="notice">This popover uses entry and exit transitions.</div></main>
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
@starting-style11711712917.5
transition-behavior11711712917.4

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.

Notes

  • Top-layer animation must preserve keyboard behavior, focus handling, and a reduced-motion alternative.
  • Test the example with real content, keyboard input, browser zoom, and the narrowest layout your project supports.
  • Use a fallback when the support table shows that one of your required browsers predates the feature.

Conclusion

Entry and exit transitions require explicit handling because newly rendered and hidden elements do not have an ordinary previous rendered state. Starting styles provide the entry value, while discrete transition behavior keeps display and top-layer changes synchronized with opacity and transform.

Treat this pattern as state management expressed in CSS: define the hidden state, visible state, starting state, and the exact point at which discrete properties change.

PreviousCSS TransitionsNextCSS Animations