October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Create Responsive Animations with CSS

Build animations that adapt to viewport and component size, respect reduced-motion preferences, and avoid unnecessary layout work.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make animation respond to the condition that matters: use a viewport media query when the overall screen size or device setting should change the effect, and a container query when a reusable component should respond to the space available inside its own container. Then provide a reduced-motion alternative and favor efficient animated properties such as transform and opacity when they suit the effect.

Choose between a viewport query and a container query

Responsive animation is motion that adapts to its context—such as the viewport, a component’s available space, or a person’s motion preference—rather than assuming one layout and one effect suit every situation.

Use When it fits Example
Viewport media query The overall viewport size or a browser/device feature determines the change. Use a short slide-in on wide screens but a subtler fade on narrow screens.
Container query A reusable component should respond to the size of its containing element, which may differ from the viewport. A card animates its details differently in a narrow sidebar than in a wide content column.

Media queries apply conditional styling based on viewport values and browser or device features, and are a key part of responsive design. Container queries instead let a component respond to its container’s size. This is especially useful when the same component can appear in different width contexts. See MDN’s media query guide and MDN’s container query guide.

Example: viewport-controlled motion

This animation changes from a modest entrance effect on wider screens to a simple fade on narrow screens. The example assumes the animation is triggered by adding a class; it does not automatically run until that class is present.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.notice {
  opacity: 0;
  transform: translateY(0.75rem);
}

.notice.is-visible {
  animation: enter 240ms ease-out both;
}

@keyframes enter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 40rem) {
  .notice.is-visible {
    animation-name: fade-in;
    animation-duration: 160ms;
  }
}

@keyframes fade-in {
  to { opacity: 1; }
}

Example: container-controlled motion

Set a container context on the component’s wrapper. The query then responds to that wrapper’s width, not the whole viewport.

.card-region {
  container-type: inline-size;
}

.card__details {
  opacity: 0;
  transform: translateY(0.5rem);
}

.card.is-open .card__details {
  animation: reveal 200ms ease-out both;
}

@keyframes reveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@container (max-width: 24rem) {
  .card.is-open .card__details {
    animation-duration: 120ms;
    animation-name: fade-in;
  }
}

Choose thresholds based on where the design actually needs to change, then test the component in each context where it is used. Container queries and newer animation features can vary across browser versions; check compatibility against your project’s target browser matrix rather than assuming universal support.

Respect reduced-motion preferences

The prefers-reduced-motion media feature reflects a user or operating-system preference to minimize nonessential movement. It has two values: reduce and no-preference. A reduced-motion treatment can remove or shorten decorative movement while retaining the information and functionality that motion might otherwise communicate. MDN documents the feature and its values in its prefers-reduced-motion reference.

A straightforward approach is to define the ordinary effect and override it for users who request reduced motion:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.notice.is-visible {
  animation: enter 240ms ease-out both;
}

@media (prefers-reduced-motion: reduce) {
  .notice.is-visible {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

If animation is an enhancement, another option is to make the static state the default and opt in to motion only for people with no reduced-motion preference:

.notice {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: no-preference) {
  .notice.is-visible {
    animation: enter 240ms ease-out both;
  }
}

Use the pattern that fits the component’s baseline state. In either case, test that content remains visible and usable when motion is disabled. W3C WAI’s Technique C39 describes the objective as: “The objective of this technique is to allow users to prevent animations (including motion animations) from being displayed on web pages, via the use of the prefers-reduced-motion CSS Media Query.” C39 is an example technique related to WCAG 2.2 Success Criterion 2.3.3, not a mandatory method of conformance; see W3C WAI Technique C39.

Keep the effect, remove the unnecessary movement

Reduced motion does not mean every animation must disappear. Preserve essential information and functionality: if movement is the only way a state or change is communicated, provide another clear cue such as a visible label, focus state, or immediate content change. W3C’s guidance distinguishes essential animation from nonessential animation; essentiality depends on whether removing the motion would fundamentally change information or functionality that cannot be achieved another conforming way. See W3C’s understanding guidance for Animation from Interactions.

Distinguish user-triggered motion from automatic animation

Animation that starts after a user interaction and animation that begins automatically are treated under different WCAG criteria. WCAG 2.2 Success Criterion 2.3.3 concerns nonessential animation triggered by interaction. Automatically initiated motion is addressed by a different criterion, so do not assume that handling interaction-triggered effects alone covers every moving element on a page. W3C’s explanation also notes that movement required to bring newly scrolled content into view is essential to scrolling, while additional decorative movement is not automatically essential. Consult W3C’s understanding guidance when deciding what the effect needs to do.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For any effect, identify what triggers it and what information it conveys. If a decorative transition can be removed without changing meaning or functionality, make it reducible. If the animation communicates a state change, ensure the state remains understandable without motion.

Choose properties with rendering cost in mind

Animation can take more processing as effects grow in size or number. Where the design permits, favor transform and opacity over properties that change layout, such as width, height, padding, margin, top, or left. Changes to dimensions and layout positions can trigger reflow and repaint. filter may be appropriate for some effects, but its cost depends on the actual effect and should be checked in context. MDN covers these practical considerations in its animation performance guide.

  • Remove animation that does not help communicate or support an interaction.
  • Prefer a transform or opacity effect when it achieves the intended result.
  • Check actual behavior on target devices; choosing a property does not guarantee every animation will be smooth in every situation.
  • Use will-change only as a last resort after identifying an existing performance problem, not as a default optimization.

CSS animations are suitable for many declarative effects, but CSS is not universally superior to JavaScript. When an effect needs programmatic control, the Web Animations API can connect JavaScript to CSS animations. MDN recommends CSS animations where possible for essential DOM animations, while recognizing that the appropriate implementation depends on the effect and the control it requires.

Test responsive and reduced-motion states

  1. Test at the viewport widths where your layout changes, including widths just above and below each breakpoint.
  2. For reusable components, place the component in both narrow and wide containers within the same viewport and verify that its container query responds as intended.
  3. Enable reduced motion in the operating system or browser, then reload or replay the interaction. Confirm that content is visible, controls still work, and state changes remain clear.
  4. Check both automatic and interaction-triggered animation, including repeated interactions and content that enters the page while scrolling.
  5. Test on the browser and device versions in your project’s support matrix. Verify newer CSS features rather than assuming a fixed compatibility set.
  6. If an effect performs poorly, simplify or remove unnecessary motion, then profile the actual page before adding optimizations such as will-change.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

To capture a rendered page for visual review, one GET request to ScreenshotNeo returns a PNG, JPEG, WebP, or PDF. For example, capture a page as WebP with cURL:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Blank Flip Book Paper with Holes - 240 Sheets (480 Pages) Flipbook Animation Paper : Works with Flip Book Kit Light Pads: for Drawing, Sketching Supplies/Comic Book Kit - Drawing Paper Animation Kit
  • Complete animation paper set … A great animation starter kit! Our 240 sheet (480 pages) flipbook paper with holes is quality 4.5inch x 2.5inch 120 gsm flippable paper and binding screws!
  • Perfect starter kits ... No more making your own flipbooks with scraps and staples. Our kits come with 2 sizes of binding screws, allowing you to trace and make flipbooks of many different sizes!
  • Individual pages ... Creating your own movies and animation has never been easier. No more limits on your animations that sewn binding books give you - With individual pages YOU get to decide!
  • Tracing made easy ... With our beautiful thick individual pages it is much easier to use with a light source, such as flip book light pads (not included) to trace your animations
  • Easy drawing ... No more spiral binding or pesky sewn book spines getting in your way. Our sketch pad paper is individual and free, just like your stop motion animations
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for API options. ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses include headers that identify the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for AI agents and other MCP clients. The free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Does reduced motion mean an animation must always be removed?

No. Reduce or remove nonessential movement while preserving essential information and functionality; where needed, communicate state changes without relying on motion.

Should I use CSS or JavaScript for animation?

Use CSS for suitable declarative effects; use JavaScript or the Web Animations API when the effect needs programmatic control. Neither approach is the universal winner.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.