Responsive iframe / video embed

Modern CSS aspect-ratio makes an embedded iframe (YouTube, a map) responsive while preserving its proportions at any screen width.

Code

<div style="aspect-ratio: 16 / 9; width: 100%;">
  <iframe
    src="https://www.youtube.com/embed/VIDEO_ID"
    title="Video"
    style="width: 100%; height: 100%; border: 0;"
    loading="lazy"
  ></iframe>
</div>

Explanation

aspect-ratio on the parent div forces it to always keep a 16:9 ratio, and the iframe fills that container's full width/height.

  • The older technique without aspect-ratio: padding-top:56.25% on the container plus position:absolute on the iframe — needed only for very old browser support.

Related tools