Style Media States Without JavaScript: What Edge 158 Changes
- Get link
- X
- Other Apps
Style Media States Without JavaScript: What Edge 158 Changes
Small media-player details often create surprising amounts of JavaScript. A card needs a glow while its video is playing, a loading indicator should appear during buffering, and a paused item needs a different visual treatment. Traditionally, code listens for media events and adds or removes classes.
Microsoft Edge 158, scheduled for November 19, 2026, adds media-state pseudo-classes that let CSS observe these states directly: :playing, :paused, :seeking, :buffering, :stalled, :muted, and :volume-locked. This is a useful reduction in state-management code, but it is not a reason to remove JavaScript blindly: MDN currently marks the selectors as limited availability, so a progressive enhancement strategy is still necessary.
A small example
Give the media element a meaningful container and keep the normal appearance as the fallback:
<article class="media-card"> <video controls preload="metadata" poster="lesson-poster.jpg"> <source src="lesson.mp4" type="video/mp4" /> <track src="lesson-en.vtt" kind="subtitles" srclang="en" label="English" /> <p>Your browser cannot play this video. <a href="lesson.mp4">Download it</a>.</p> </video> <p class="media-status" aria-live="polite">Ready to play</p> </article> .media-card { border: 2px solid #d6dbe1; border-radius: 0.75rem; padding: 0.75rem; transition: border-color 160ms ease, box-shadow 160ms ease; } .media-status { color: #59636e; font-size: 0.9rem; } @supports selector(video:playing) { video:playing { outline: 3px solid #2f80ed; outline-offset: 3px; } .media-card:has(video:playing) { border-color: #2f80ed; box-shadow: 0 0 0 4px rgb(47 128 237 / 15%); } .media-card:has(video:buffering), .media-card:has(video:stalled) { border-color: #d97706; } .media-card:has(video:paused) { border-color: #8b95a1; } } The @supports selector(...) feature query keeps the enhanced rules together and allows older browsers to retain the base design. The :has() relationship selector lets the card respond to the state of its descendant video. If the browser does not support either selector, the card remains usable rather than losing its styling.
What the states mean
:playingmatches media that is playing. MDN notes that it can continue to match while playback is temporarily interrupted by conditions such as buffering.:bufferingmeans the media cannot continue because it is waiting for enough data. It also matches:playing, so do not use those selectors as mutually exclusive states.:stalledis useful for a different failure or waiting treatment, but the UI should not imply that the application can repair every network problem.:pausedcan provide a quiet visual state without apauseevent handler.
These selectors describe the browser's media state; they do not replace the media controls, captions, error handling, or a product-specific status model. Keep the actual <audio> or <video> element accessible, provide captions where appropriate, and preserve a text or download fallback.
When JavaScript is still the right tool
CSS is a good fit when the only requirement is presentation: change a border, reveal a spinner, or dim a card. Use JavaScript when the state must drive behavior or text that CSS cannot supply, such as analytics, synchronizing a playlist, updating a custom control's accessible name, retrying a failed request, or coordinating several independent media elements.
If a custom status message is important, do not assume that a color or animation communicates it. A small event-driven layer can update an aria-live region, while CSS handles visual decoration where supported:
const video = document.querySelector("video"); const status = document.querySelector(".media-status"); video.addEventListener("waiting", () => { status.textContent = "Buffering…"; }); video.addEventListener("playing", () => { status.textContent = "Playing"; }); video.addEventListener("pause", () => { status.textContent = "Paused"; }); This is not a contradiction. The best migration is often to remove class-toggling code while retaining JavaScript for semantics and application behavior. Let CSS describe appearance, and let JavaScript handle information or actions that must be exposed beyond appearance.
How to adopt it safely
- Start with a useful fallback that does not depend on the new selectors.
- Put only presentational enhancements inside
@supports selector(video:playing). - Test the transitions that matter: play, pause, seek, buffering, stalled playback, muted playback, and an unavailable media source.
- Check keyboard operation, captions, focus indicators, reduced-motion preferences, and the contrast of every state.
- Use browser compatibility data and real target browsers before deleting existing event-driven behavior.
Edge 158 makes media-state styling more direct, and the selectors are now documented as part of the evolving web platform. The durable lesson is broader than this release: use browser state in CSS when the job is visual, feature-detect it, and keep JavaScript for behavior and accessibility that CSS cannot express.
References
- Microsoft Edge 158 web platform release notes — release timing and the new media pseudo-classes.
- MDN:
:playing— matching semantics and compatibility status. - MDN:
:buffering— buffering semantics and its relationship to:playing. - MDN:
@supports— feature queries for progressive enhancement. - CSS Selectors Level 4 — the standards context for CSS selector behavior.
❤️ Support This Blog
If this post helped you, you can support my writing with a small donation. Thank you for reading.
- Get link
- X
- Other Apps

Comments
Post a Comment