How to get a video element to act like background-size: cover scoped within a parent element.

<section class="container">
  <video class="fullscreen" src="" playsinline autoplay muted loop>

  <div class="content">
video.fullscreen {
  position: absolute;
  z-index: 0;
  object-fit: cover; // this is the key
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  &::-webkit-media-controls {
     display:none !important;

.container {
   position: relative;
   display: grid;
   place-items: center;
   height: 70vh;
   width: 70vw;
   margin: 0 auto;
   background: #ccc;

.content {
  z-index: 1;

See the Pen CSS Video Background Cover by Kevin Dees (@kevindees) on CodePen.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.