Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="video-container">
  <div class="lazy-loading-content image-container">
    <!--     add Youtube ID  -->
    <img src="https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg" class="video-thumbnail" />
    <div class="play-button">
    </div>
  </div>
</div>
              
            
!

CSS

              
                $spacer: 2rem;

.video-container {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: $spacer;
  padding: $spacer;

  &:hover {
    cursor: pointer;
    .play-button {
      filter: none;
    }
  }

  .image-container {
    width: 100%;
    position: relative;

    img {
      vertical-align: middle;
      width: 100%;
      height: auto;
    }
  }
}

.play-button {
  width: 68px;
  height: 48px;
  position: absolute;
  transform: translate3d(-50%, -50%, 0);
  top: 50%;
  left: 50%;
  z-index: 1;
  background-color: transparent;
  /* youtube's actual play button svg */
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 68 48"><path fill="%23f00" fill-opacity="0.8" d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z"></path><path d="M 45,24 27,14 27,34" fill="%23fff"></path></svg>');
  filter: grayscale(100%);
  transition: filter 0.1s cubic-bezier(0, 0, 0.2, 1);
  border: none;
}

              
            
!

JS

              
                // update variable with the Youtube ID
const videoID = "dQw4w9WgXcQ";

// selects the parent container
const parentContainer = document.querySelector(".video-container");

// When the parent container is clicked
parentContainer.addEventListener("click", function () {
  // remove the image container
  const lazyLoadingChild = document.querySelector(".lazy-loading-content");
  parentContainer.removeChild(lazyLoadingChild);

  // create a new responsive video container
  const responsiveVideoContainer = document.createElement("div");

  // apply responsive classes from bootstrap
  responsiveVideoContainer.classList.add(
    "embed-responsive",
    "embed-responsive-16by9"
  );

  // create the iFrame with the video embed
  const videoIframe = document.createElement("iframe");

  videoIframe.classList.add("embed-responsive-item");

  videoIframe.src = `https://www.youtube.com/embed/${videoID}?autoplay=1&mute=1`;

  videoIframe.setAttribute("allow", "autoplay");

  // add the iFrame to the video container
  responsiveVideoContainer.appendChild(videoIframe);

  // add the video container to the parent container
  parentContainer.appendChild(responsiveVideoContainer);
});

              
            
!
999px

Console