Make YouTube and Vimeo iframes scale to the width of their container and keep a 16:9 shape on every screen.
iframe[src*="youtube.com"],
iframe[src*="youtube-nocookie.com"],
iframe[src*="player.vimeo.com"] {
width: 100%;
height: auto;
aspect-ratio: 16 / 9;
}
Embedded videos often come with fixed widths and heights, so they overflow on phones or leave black bars. This CSS makes them fill their container and keep the right shape.
The selectors match iframes from YouTube, YouTube’s privacy-enhanced domain and Vimeo. Setting the width to 100% and the height to auto, then fixing the aspect-ratio to 16:9, lets the browser work out the height from the width at any screen size.
responsive-embeds. This helps with embeds pasted as HTML, page builders and older themes.aspect-ratio: 9 / 16.Embed a YouTube video and resize the browser window, or view the page on a phone. The video should fit the width without black bars.