aspect-video requests a 16:9 box. Combine it with a flexible width and decide how differently shaped media should fit inside that box.
Version and setup
These examples are compiled with Tailwind CSS 3.3.2. Copy document includes the required CSS, so that document runs without a Tailwind installation. To use the utility classes in a project, follow the versioned setup guide.
This site customizes its spacing scale: p-10 is 10px here, while standard Tailwind 3 uses 2.5rem. The examples below use unaffected spacing keys or explicit arbitrary values. Check your project configuration before assuming a utility’s size. Tailwind 4 has a different setup; use its official installation guide for a new version-4 project.
Play a responsive video
Tailwind CSS 3.3.2; the CSS tab includes the compiled styles.
HTML
<p class="mb-4">Video description: blue changes to green after one second; there is no audio.</p>
<video class="w-full aspect-video object-contain bg-black" controls playsinline preload="metadata" width="320" height="180" aria-label="Silent color-change demonstration"><source src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAOTbW9vdgAAAGxtdmhkAAAAAAAAAAAAAAAAAAAD6AAAB9AAAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAr10cmFrAAAAXHRraGQAAAADAAAAAAAAAAAAAAABAAAAAAAAB9AAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAKAAAABaAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAAfQAAAgAAABAAAAAAI1bWRpYQAAACBtZGhkAAAAAAAAAAAAAAAAAABAAAAAgABVxAAAAAAALWhkbHIAAAAAAAAAAHZpZGUAAAAAAAAAAAAAAABWaWRlb0hhbmRsZXIAAAAB4G1pbmYAAAAUdm1oZAAAAAEAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAaBzdGJsAAAAwHN0c2QAAAAAAAAAAQAAALBhdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAKAAW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nNldD0tMiB0aHJlYWRzPTMgbG9va2FoZWFkX3RocmVhZHM9MSBzbGljZWRfdGhyZWFkcz0wIG5yPTAgZGVjaW1hdGU9MSBpbnRlcmxhY2VkPTAgYmx1cmF5X2NvbXBhdD0wIGNvbnN0cmFpbmVkX2ludHJhPTAgYmZyYW1lcz0zIGJfcHlyYW1pZD0yIGJfYWRhcHQ9MSBiX2JpYXM9MCBkaXJlY3Q9MSB3ZWlnaHRiPTEgb3Blbl9nb3A9MCB3ZWlnaHRwPTIga2V5aW50PTI1MCBrZXlpbnRfbWluPTQgc2NlbmVjdXQ9NDAgaW50cmFfcmVmcmVzaD0wIHJjX2xvb2thaGVhZD00MCByYz1jcmYgbWJ0cmVlPTEgY3JmPTIzLjAgcWNvbXA9MC42MCBxcG1pbj0wIHFwbWF4PTY5IHFwc3RlcD00IGlwX3JhdGlvPTEuNDAgYXE9MToxLjAwAIAAAAA2ZYiEABP//urj/MstsBc2CqWqI419bldTT0hMRL3GW2p9vz+1MlfKUX2po6nubIEjAAQIDZx5AAAAF0GaJGOeB+ApQOgD/A/A3QS//rUqgB4wAAAADUGeQniCX+YIex60zYEAAAAJAZ5hdEEPACDgAAAADAGeY2pBD+j0PGnRfwAAABJBmmdJqEFomUwIIf/+qlUAPGEAAAALQZ6FRREsEf8AEXEAAAAJAZ6makEPACDh" type="video/mp4"></source></video>
CSS
*,
::before,
::after {
box-sizing: border-box;
border: 0 solid #e5e7eb;
}
h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
margin: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: inherit;
font-weight: inherit;
}
button,
input,
select,
textarea {
font: inherit;
color: inherit;
}
button {
background: none;
}
img,
svg,
video {
display: block;
max-width: 100%;
}
img,
video {
height: auto;
}
a {
color: inherit;
text-decoration: inherit;
}
ol,
ul,
menu {
list-style: none;
margin: 0;
padding: 0;
}
.mb-4 {
margin-bottom: 1rem;
}
.aspect-video {
aspect-ratio: 16 / 9;
}
.w-full {
width: 100%;
}
.bg-black {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
.object-contain {
object-fit: contain;
}
Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.
The embedded clip runs without a third-party player. Native controls let the reader start and stop it. object-contain preserves the video’s shape; a differently shaped clip would leave empty space rather than crop it.
If you embed a provider’s player
For an iframe, use a titled embed inside an aspect-video wrapper, with w-full h-full on the iframe and a removed border. Use the provider’s actual embed URL and permissions. Network access, consent settings and the provider’s availability remain dependencies; an aspect-ratio rule cannot make a blocked player work.
This lesson previously depended on an external player that failed during local verification. The stable clip teaches sizing without that dependency. Supply captions and other alternatives when the content needs them. Compare native aspect-ratio and video.
Sources
Reference 1 Reference 2 Reference 3 provide the technical details and current compatibility information.