Styling
Basics
In this section, we'll cover the basics on how you can style elements with CSS based on specific media states.
Introduction
The player exposes media state as attributes and CSS variables on the <vds-media>
element:
You can use the presence and absence of these attributes to style children of the <vds-media>
element with CSS. Here's a few simple examples:
[attr]
selects elements based on the presence or value of an attribute, and the :not()
pseudo-class represents elements that do not match a list of selectors. We can combine these to create powerful selectors based on the media state being exposed and updated on the <vds-media>
element.
Media Attributes
Here's a reference table that displays all the media attributes that are set on the <vds-media>
element.
Attribute | Description |
---|---|
autoplay | Autoplay has successfully started. |
autoplay-error | Autoplay has failed to start. |
can-load | Media can begin loading. |
can-play | Media is ready to be played. |
can-fullscreen | Media fullscreen is available. |
ended | Playback has reached the end. |
error | Issue with media loading/playback. |
fullscreen | Media is in fullscreen mode. |
user-idle | User is not active during playback. |
loop | Media is set to loop back to start on end. |
muted | Media is muted. |
paused | Playback is in a paused state. |
playing | Playback has started or resumed. |
playsinline | Media should play inline by default (iOS Safari). |
seeking | Media or user is seeking to new playback position. |
started | Media playback has started. |
waiting | Media is waiting for more data (i.e., buffering). |
ios-controls | iOS media controls are visible. |
Media CSS Variables
Here's a reference table that displays all the media CSS variables that are set on the <vds-media>
element.
Variable | Description |
---|---|
--media-buffered-amount | The amount of media that has buffered in seconds (0 -> duration). |
--media-current-time | The current playback time in seconds (0 -> duration). |
--media-duration | The total length of media in seconds. |
--media-seekable-amount | The amount of media that is seekable in seconds (0 -> duration). |