Styling a custom video or audio player used to mean JavaScript for everything: listen for play, pause, waiting and volumechange events, then toggle classes so your CSS knows what’s happening. That’s no longer necessary. The media element pseudo-classes, :playing, :paused, :seeking, :buffering, :stalled, :muted and :volume-locked, are now Baseline Newly available.

The web-features 3.48.0 release moved the feature to Baseline Newly available, with a Baseline date of 19 November 2026, the day Edge 158 shipped. The support data lists Safari 15.4, Firefox 150, and Chrome and Edge 158. This tutorial builds a small custom video player whose controls are styled entirely from the media element’s state.

What each pseudo-class matches

All seven match <audio> and <video> elements. Definitions are from MDN:

Pseudo-class Matches when the element…
:playing is playing, or has stopped temporarily for reasons other than the user (buffering or stalled)
:paused is paused by the user or hasn’t started yet
:seeking is moving to a new playback position
:buffering can’t continue because it’s waiting for more data
:stalled has received no data for a while (about 3 seconds, depending on the browser)
:muted is muted
:volume-locked has its volume locked by the operating system or browser

Two details are easy to miss:

  • :buffering and :stalled also match :playing. A buffering video is still “playing” in spec terms. So put your buffering styles after your playing styles, or make them more specific.
  • :volume-locked means scripts can’t change the volume or mute state, because the operating system or browser controls it. Hide your volume slider in that state.

The HTML

A wrapper holds the video and a simple control bar. We use the :has() selector (Baseline since 2023) so the wrapper can react to the video’s state:

<figure class="player">
  <video src="/media/intro.mp4" preload="metadata" playsinline></video>

  <div class="spinner" aria-hidden="true"></div>

  <div class="controls">
    <button class="play" type="button" aria-label="Play or pause">
      <span class="icon-play">▶</span>
      <span class="icon-pause">❚❚</span>
    </button>
    <button class="mute" type="button" aria-label="Mute or unmute">
      <span class="icon-sound">🔊</span>
      <span class="icon-muted">🔇</span>
    </button>
    <input class="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="Volume">
  </div>
</figure>

The CSS: state without classes

.player {
  position: relative;
  max-width: 720px;
}

.player video {
  display: block;
  width: 100%;
  border-radius: 12px;
}

/* Play / pause icon swap */
.player .icon-pause { display: none; }
.player:has(video:playing) .icon-play { display: none; }
.player:has(video:playing) .icon-pause { display: inline; }

/* Show the controls while paused, fade them while playing */
.player .controls { transition: opacity 0.3s; }
.player:has(video:playing) .controls { opacity: 0.2; }
.player:has(video:playing):hover .controls,
.player:has(video:playing):focus-within .controls { opacity: 1; }

/* Loading spinner while buffering or seeking */
.player .spinner { display: none; }
.player:has(video:buffering) .spinner,
.player:has(video:seeking) .spinner {
  display: block;
}

/* Network problem: make it obvious */
.player:has(video:stalled) video {
  outline: 3px solid orange;
}

/* Mute icon swap */
.player .icon-muted { display: none; }
.player:has(video:muted) .icon-sound { display: none; }
.player:has(video:muted) .icon-muted { display: inline; }

/* The volume can't be changed by script: hide the slider */
.player:has(video:volume-locked) .volume { display: none; }

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .player .controls { transition: none; }
}

Notice that the CSS never needs a class like .is-playing. The browser keeps the pseudo-classes in sync with the real media state, including changes that don’t come from your buttons. For example, when the user presses a hardware media key, or a picture-in-picture window pauses the video, the styles still update.

The JavaScript: actions only

JavaScript is still needed for the buttons, but it no longer tracks state:

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

player.querySelector(".play").addEventListener("click", () => {
  if (video.paused) {
    video.play();
  } else {
    video.pause();
  }
});

player.querySelector(".mute").addEventListener("click", () => {
  video.muted = !video.muted;
});

player.querySelector(".volume").addEventListener("input", (event) => {
  video.volume = Number(event.target.value);
});

There are no play, pause, waiting or volumechange listeners to keep in sync, so the styles can’t drift away from the real state of the video.

Fallbacks for older browsers

“Baseline Newly available” means the feature works in the latest version of every major browser. People on older Chrome or Edge versions (before 158) won’t match these selectors. Two simple strategies:

1. Make the default state usable. In the CSS above, the default (no pseudo-class matched) shows the play icon and the full controls. Older browsers get a working, if less dynamic, player.

2. Use @supports selector() for a class-based fallback only where you need it:

@supports not selector(:playing) {
  .player.is-playing .icon-play { display: none; }
  .player.is-playing .icon-pause { display: inline; }
}
if (!CSS.supports("selector(:playing)")) {
  video.addEventListener("play", () => player.classList.add("is-playing"));
  video.addEventListener("pause", () => player.classList.remove("is-playing"));
}

You can delete this fallback once your analytics show that older browsers are no longer a concern.

Testing tips

  • In Chrome DevTools, use the Network panel’s throttling to trigger :buffering. Cutting the connection mid-playback should eventually show :stalled.
  • Seek with the keyboard or by setting video.currentTime in the console to see :seeking.
  • Test :volume-locked on devices where the system controls media volume, such as phones and tablets, and check that the slider disappears.

Accessibility notes

Pseudo-classes only change styles, so keep the buttons’ accessible names meaningful. A good pattern is to update aria-label or aria-pressed in the same click handler that toggles playback. The video element also keeps its native keyboard behaviour. If you hide the native controls, make sure your custom buttons can be reached with Tab and work with Enter and Space, which <button> gives you for free.

Takeaway

The media pseudo-classes let CSS react directly to what a video or audio element is doing: playing, buffering, stalled, muted or volume-locked. Combined with :has(), they replace most of the state-tracking JavaScript in custom players. Use them now with a usable default for older browsers, and check the details on MDN’s :playing reference and the related pages for each pseudo-class.