Skip to content
back to blog
developmentDecember 6, 2026 · 3 min read

CSS Media Pseudo-Classes: Style Your Video Player Without Event Listeners

With :playing, :paused, :buffering and :muted now Baseline, your custom video controls can read player state from CSS instead of six event listeners.

Dan Holloran
Dan Holloran
Senior Fullstack Developer
CSS Media Pseudo-Classes: Style Your Video Player Without Event Listeners

Every custom video player I've built has the same block of glue code near the top. Listen for play, add is-playing to the wrapper. Listen for pause, take it off. Listen for waiting, show a spinner. Listen for playing, hide it again. Listen for volumechange, flip a muted icon. None of it is interesting, and all of it can drift: miss one event and your play button says "pause" while the video sits still.

As of November 19, 2026, you can delete most of that. The media element pseudo-classes (:playing, :paused, :seeking, :buffering, :stalled, :muted, and :volume-locked) are Baseline Newly available. Safari has shipped them since 15.4, Firefox added them in 150, and Chrome and Edge 158 closed the gap this November as part of Interop 2026. The browser already knows what the video is doing; now CSS can ask it.

The seven states, and the one gotcha ​

Most of these do what the name says. :paused and :playing are opposites: one matches when the element's paused property is true, the other when it isn't. :muted tracks the muted property. :seeking matches while the user scrubs to a new position.

The gotcha is :buffering and :stalled. Per MDN, a buffering element is "still considered to be :playing." Same for stalled. :playing means "the user asked it to play," not "frames are advancing." So if you write this:

css
video:playing ~ .controls .pause-icon {
  display: block;
}
video:buffering ~ .controls .spinner {
  display: block;
}

you get the pause icon and the spinner at the same time during a network hiccup. That might be what you want. If not, be explicit:

css
video:playing:not(:buffering, :stalled) ~ .controls .pause-icon {
  display: block;
}

:volume-locked is the odd one out. It matches when the operating system or user agent owns the volume, so script can't change it. iOS is the familiar case. That makes it the right hook for hiding a volume slider that would otherwise do nothing:

css
video:volume-locked ~ .controls .volume-slider {
  display: none;
}

Wiring it into real controls ​

One structural constraint: children of <video> never render, so you can't nest your controls inside it. Put them next to the video and reach them with a sibling combinator, or style the wrapper with :has():

html
<div class="player">
  <video src="/talk.mp4" preload="metadata"></video>
  <div class="controls">
    <button class="toggle" type="button">
      <span class="label-play">Play</span>
      <span class="label-pause">Pause</span>
    </button>
    <span class="spinner" aria-hidden="true"></span>
  </div>
</div>
css
.label-pause,
.spinner {
  display: none;
}

.player:has(video:playing) .label-play {
  display: none;
}
.player:has(video:playing) .label-pause {
  display: inline;
}

.player:has(video:buffering, video:stalled) .spinner {
  display: block;
}

/* Dim the chrome while playing, bring it back on hover or focus */
.player:has(video:playing) .controls {
  opacity: 0;
  transition: opacity 200ms;
}
.player:has(video:playing):is(:hover, :focus-within) .controls {
  opacity: 1;
}

The label swap is the part I like most. Elements with display: none are left out of accessible name computation, so the button's name changes from "Play" to "Pause" for screen readers too, with no aria-label bookkeeping in JavaScript.

What CSS can't do is act. You still need a few lines to make the button work:

js
const player = document.querySelector(".player");
const video = player.querySelector("video");

player.querySelector(".toggle").addEventListener("click", () => {
  video.paused ? video.play() : video.pause();
});

That's the whole script. It changes state, and CSS reflects it. One direction, one source of truth.

Shipping it without breaking older browsers ​

"Newly available" means the latest versions of every major engine. It doesn't mean your users are on them. Anyone on Chrome 157 or older parses :playing as an unknown selector and drops the whole rule. Since .player:has(video:playing) sits in its own rule, the damage stays contained: the play label stays visible and the button still works. That's a fine floor for many sites.

If you need the full experience everywhere for now, feature-detect and keep the class-toggle path as a fallback:

js
if (!CSS.supports("selector(:playing)")) {
  const sync = () => {
    player.classList.toggle("is-playing", !video.paused);
    player.classList.toggle(
      "is-buffering",
      video.readyState < 3 && !video.paused,
    );
  };
  ["play", "pause", "waiting", "playing", "canplay"].forEach((e) =>
    video.addEventListener(e, sync),
  );
}

Then list both selectors, each in its own rule so an unsupported pseudo-class can't sink the class-based one:

css
.player.is-playing .label-play {
  display: none;
}
.player:has(video:playing) .label-play {
  display: none;
}

When your analytics say the old browsers are gone, delete the fallback block and the duplicate rules. Usage of these selectors is still tiny (around 0.04% of page loads, per Chrome Platform Status), so you're early, but this is the kind of feature that quietly removes a whole category of state bugs.

If you maintain a player component, try one thing this week: replace the is-playing class with :has(video:playing) behind an @supports selector(:playing) block and see how much of your listener code you can retire. The MDN pages for each pseudo-class and the Selectors Level 4 spec cover the exact matching rules.

~/subscribe
# new posts on code, craft & travel — no noise, no schedule