Learn how to customize the look and feel of Mux Player to fit your brand and use case.
By default Mux Player will pull the default poster image from the middle of the video based on the Playback ID that you provide. The default poster image is the mid-point of the Mux asset.
https://image.mux.com/{PLAYBACK_ID}/thumbnail.jpg
If you want to change the poster image, you have two options:
Pass in thumbnail-time
(React: thumbnailTime
) with the value in seconds of the thumbnail that you want to pull from the video.
thumbnail-time
attribute and corresponding React prop are only available if you're NOT using Signed URLs.time=
parameter to your signed token (see the Usage with signed URLs guide).Use the poster=
attribute (both HTML element and React).
<video>
element. For the best viewer experience, your poster image should match the aspect ratio of the video.While the poster image loads, Mux Player will display the contents of the placeholder=
attribute. Consider using a Data URL so that the placeholder is immediately available without a network request.
If you are generating your pages with a Node.js server (like Next.js), you can generate Data URLs for Mux Videos with the @mux/blurup
package.
The Data URLs generated by @mux/blurup
contain lightweight multicolor gradients that visually represent what the default poster image will look like once it has fully loaded.
For example:
// Server-Side
import { createBlurUp } from '@mux/blurup';
const options = {};
const muxPlaybackId = 'O6LdRc0112FEJXH00bGsN9Q31yu5EIVHTgjTKRkKtEq1k';
const getPlaceholder() = async () => {
const { blurDataURL, aspectRatio } = await createBlurUp(muxPlaybackId, options);
console.log(blurDataURL, aspectRatio);
// data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" ...
};
<!-- Client-Side -->
<mux-player
playback-id="{playbackId}"
placeholder="{blurDataUrl}"
style="aspect-ratio: {aspectRatio}"
></mux-player>
If you change the thumbnail time with thumbnailTime
, you should also pass a time configuration to createBlurUp(playbackId, { time: customThumbTime })
to generate the correct placeholder.
You can learn more about @mux/blurup
on GitHub.
If you have a client-side-only application and you can't generate a blur placeholder, you might want to pass a smaller resolution poster image URL as the placeholder value that will load more quickly than the final hi-res poster.
Use the title
attribute (title
prop in React) to add a visible title in the top left corner on Mux Player. Note that this is different that metadata-video-title
, which is a Mux Data metadata field.
Mux Player HTML element can be styled and positioned with CSS just like you would any other HTML element. For example:
mux-player {
width: 100%;
max-width: 800px;
margin: 40px auto;
}
In React, you can style the <MuxPlayer>
component the same way you style other components; with styled-components or directly with the style=
prop.
The Mux API will provide you the aspect ratio of your video in the form of w:h
. You should save this aspect_ratio
in your database or CMS alongside the playback_id
and other asset details. Then you can use that with CSS in the form of w / h
. This is using the CSS aspect-ratio property which is supported in all evergreen browsers.
Setting the aspect ratio of the player is important for preventing Cumulative Layout Shift on the page.
mux-player {
aspect-ratio: 16 / 9;
}
You can add rounded corners to the player by wrapping it in a div
with the style
attribute set to border-radius
.
<div style="border-radius: 10px; overflow: hidden; display: flex;">
<mux-player></mux-player>
</div>
You can change the way that video is sized within its <video>
element. Mux Player provides two css variables that you can use to override the standard object-fit
and object-position
css properties.
mux-player {
--media-object-fit: cover;
--media-object-position: center;
}
By default, Mux Player will show all the controls associated with the current player size and stream type.
To hide certain controls, use CSS variables like this:
--seek-backward-button
will control the display
of the seek backward button. Set it to none
to hide it completely.
mux-player {
--seek-backward-button: none;
--seek-forward-button: none;
}
CSS vars can also be passed inline
<mux-player
style="--seek-backward-button: none; --seek-forward-button: none;"
></mux-player>
You can target specific sections of the player by prefixing the CSS vars with the section. The following sections are available:
top
the top control bar that shows on the small player sizecenter
the center controls that show the seek forward/backward button and play buttonbottom
the bottom control bar<mux-player
style="--center-controls: none; --top-captions-button: none;"
></mux-player>
The below CSS selector shows all available CSS vars for hiding, each one can be prefixed with a section.
mux-player {
/* Hide all controls at once */
--controls: none;
/* Hide the error dialog */
--dialog: none;
/* Hide the loading indicator */
--loading-indicator: none;
/* Target all sections by excluding the section prefix */
--play-button: none;
--live-button: none;
--seek-backward-button: none;
--seek-forward-button: none;
--mute-button: none;
--captions-button: none;
--airplay-button: none;
--pip-button: none;
--fullscreen-button: none;
--cast-button: none;
--playback-rate-button: none;
--volume-range: none;
--time-range: none;
--time-display: none;
--duration-display: none;
--rendition-menu-button: none;
/* Target a specific section by prefixing the CSS var with (top|center|bottom) */
--center-controls: none;
--bottom-play-button: none;
}
Mux Player exposes a CSS variable (--controls-backdrop-color
) to set the controls backdrop color.
This is the background color that will show up behind the controls in the player.
mux-player {
--controls-backdrop-color: rgb(0 0 0 / 60%);
}
The backdrop color is turned off by default. Note if you change this color be sure to make the contrast against the controls high enough as it has implications on the accessibility of the controls as they may not meet the contrast ratio requirements for WCAG 2.1.
Mux Player uses a shadow DOM to encapsulate its styles and behaviors. As a result, it's not possible to target its internals with the usual CSS selectors. Instead, some components expose parts that can be targeted with the CSS part selector, or ::part()
.
<style>
mux-player::part(center play button) {
display: none;
}
</style>
<mux-player playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"></mux-player>
Supported parts: live
, layer
, media-layer
, poster-layer
, vertical-layer
, centered-layer
, gesture-layer
, top
, center
, bottom
, play
, button
, seek-backward
, seek-forward
, mute
, captions
, airplay
, pip
, cast
, fullscreen
, playback-rate
, volume
, range
, time
, display
.
CSS parts allow you to style each element individually with a selector like ::part(center play button)
or target multiple elements if the part is assigned to multiple elements internally, usage ::part(button)
. Every CSS property can be declared in the selector, this makes it a very powerful API.
Note that if you are using advanced styling with ::parts
selectors then be sure to test out your custom styles when upgrading to new versions of Mux Player.
The colors of Mux Player can be customized with the following options:
HTML Attribute | React Prop | Description |
---|---|---|
accent-color | accentColor | Changes the color used to accent the controls |
primary-color | primaryColor | Changes the color of the control icons |
secondary-color | secondaryColor | Sets the background color of the control bar |
Below are the attributes (Web Component) / props (React) available to enable, disable, hide, or change aspects of various controls to suit your use case.
While Mux Player defaults to enabling sound, you can pass an attribute/prop to start playback muted.
muted
(HTML element & React) is a boolean value that, when true
, defaults sound to a muted state. Users can still unmute and manage volume as desired.
The amount of time for skip forward/backward defaults to 10 seconds. This can be changed by passing the following attributes (HTML element) / props (React), which updates both the seek buttons and keyboard ("hotkey") behaviors.
Attribute (HTML) | React Prop | Description | Example |
---|---|---|---|
forward-seek-offset | forwardSeekOffset | Sets the number of seconds to skip forward | forward-seek-offset="5" will apply a 5 second skip forward |
backward-seek-offset | backwardSeekOffset | Sets the number of seconds to skip backward | backward-seek-offset="5" will apply a 5 second skip backward |
When captions are available on an asset, we show the control for them and enable their appearance by default.
You can opt to disable their appearance (while still showing the control) by using the default-hidden-captions
(HTML element) attribute or defaultHiddenCaptions
(React) prop and a boolean value.
If you'd like to set a specific time stamp as the start of playback for an asset, you can use the start-time
(HTML element) attribute or startTime
(React) prop and a time value.
When start-time
is provided, it will also be used for the thumbnail-time
if no thumbnail-time
is explicitly provided.
Example: start-time="13"
will begin playback at 13 seconds into the asset.
You can automatically loop the asset once playback completes with the loop
HTML element attribute or React prop and a boolean value.
If you have a background looping video on your page for example, you might want to: turn off all controls, autoplay, mute and loop the video:
<style>
mux-player {
--controls: none;
}
</style>
<mux-player
playback-id="23s11nz72DsoN657h4314PjKKjsF2JG33eBQQt6B95I"
autoplay="muted"
loop
></mux-player>
Autoplay in browsers is a difficult beast. See this doc if you're curious about the details. The good news is that Mux Player can help you handle autoplay when it is warranted.
Before you decide to autoplay your assets, first ask yourself: Is this necessary? Often times it negatively impacts accessibility, and many viewers find autoplay to be an impediment to their experience.
Here are your options for autoplay:
Attribute (HTML) | Prop (React) | Description | Behavior |
---|---|---|---|
autoplay | autoPlay | Basic autoplay | Will try to autoplay with sound on (likely to fail) |
autoplay="muted" | autoPlay="muted" | Muted autoplay | Will autoplay the video in muted state (likely to work) |
autoplay="any" | autoPlay="any" | Fallback autoplay | Will try autoplay with sound first, then fall back to muted if that fails |
By default, Mux Player has several keyboard shortcuts, or hotkeys, enabled. These hotkeys will only function if the player or one of the player controls are focused.
Key | Name to turn off | Behavior |
---|---|---|
Space | nospace | Toggle Playback |
c | noc | Toggle captions/subtitles track |
k | nok | Toggle Playback |
m | nom | Toggle mute |
f | nof | Toggle fullscreen |
⬅️ | noarrowleft | Seek back 10s |
➡️ | noarrowright | Seek forward 10s |
You can turn off all hotkeys or individual ones.
To turn all hotkeys off, add the nohotkeys
attribute to the Mux Player element:
<mux-player
nohotkeys
playback-id="EcHgOK9coz5K4rjSwOkoE7Y7O01201YMIC200RI6lNxnhs"
metadata-video-title="Test video title"
metadata-viewer-user-id="user-id-007"
></mux-player>
You can also do it via JavaScript:
const player = document.querySelector("mux-player");
// disable all hotkeys
player.nohotkeys = true;
// re-enable all hotkeys
player.nohotkeys = false;
If you only want to turn off specific hotkeys, you can do so via JavaScript or HTML.
Using the "Name to turn off" above, you can add those to a hotkey
attribute to turn off the specific hotkeys you don't want enabled.
For example, to turn off seeking with the arrow keys:
<mux-player
hotkeys="noarrowleft noarrowright"
playback-id="EcHgOK9coz5K4rjSwOkoE7Y7O01201YMIC200RI6lNxnhs"
metadata-video-title="Test video title"
metadata-viewer-user-id="user-id-007"
></mux-player>
You can also do this programmatically via the hotkeys
property on the element. This provides a DOM Token List, a la classList, that allows you to add or remove each key.
const player = document.querySelector("mux-player");
// turn off seeking with the arrow keys
player.hotkeys.add("noarrowright", "noarrowleft");
// re-enable the arrow keys
player.hotkeys.remove("noarrowright", "noarrowleft");
Although the ::cue
CSS selector/psuedo-element exists and has good browser support on paper, actual support of individual CSS properties when combined with it is very inconsistent. FireFox particuarly doesn't support many of them.
There are two unique CSS properties that you can use to do very basic styling of the captions text though. Combined with the ::part()
selector we can apply them like this:
mux-player::part(video) {
-webkit-text-fill-color: red;
-webkit-text-stroke: 1px blue;
}
Despite being -webkit-
prefixed, these have good cross-browser support.
Broader and more advanced support for caption styling will be available in a future version of the player.