Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


                <div id="main">
    <a href="">lite YouTube embed</a>
    tecnique renders the YouTube video inside the IFRAME tag only when the play
    button in clicked thus improving the <a href="">core web vitals</a> score of your website. Written by <a href="">@labnol</a>.

  <div class="youtube-player" data-id="ChGBcFtYdVA" />



                body {
  background: #000;
#main {
  width: 100%;
  max-width: 800px;
  margin: 30px auto 20px;
#main p {
  padding: 20px;
  margin: 20px 0;
  background: lightyellow;
.youtube-player {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  max-width: 100%;
  background: #000;
  margin: 5px;

.youtube-player iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: transparent;

.youtube-player img {
  object-fit: cover;
  display: block;
  left: 0;
  bottom: 0;
  margin: auto;
  max-width: 100%;
  width: 100%;
  position: absolute;
  right: 0;
  top: 0;
  border: none;
  height: auto;
  cursor: pointer;
  -webkit-transition: 0.4s all;
  -moz-transition: 0.4s all;
  transition: 0.4s all;

.youtube-player img:hover {
  -webkit-filter: brightness(75%);
  -moz-filter: brightness(75%);
  filter: brightness(75%);

.youtube-player .play {
  height: 48px;
  width: 68px;
  left: 50%;
  top: 50%;
  margin-left: -34px;
  margin-top: -24px;
  position: absolute;
  background: url("") no-repeat;
  cursor: pointer;



                /* Light YouTube Embeds by @labnol */
/* Web: */

function labnolIframe(div) {
  var iframe = document.createElement("iframe");
    "" + + "?autoplay=1&rel=0"
  iframe.setAttribute("frameborder", "0");
  iframe.setAttribute("allowfullscreen", "1");
    "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
  div.parentNode.replaceChild(iframe, div);

function initYouTubeVideos() {
  var playerElements = document.getElementsByClassName("youtube-player");
  for (var n = 0; n < playerElements.length; n++) {
    var videoId = playerElements[n];
    var div = document.createElement("div");
    div.setAttribute("data-id", videoId);
    var thumbNode = document.createElement("img");
    thumbNode.src = "".replace(
    var playButton = document.createElement("div");
    playButton.setAttribute("class", "play");
    div.onclick = function () {

document.addEventListener("DOMContentLoaded", initYouTubeVideos);