Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div class="tip">
   <svg height="40" viewBox="0 0 64 64" width="40" xmlns="http://www.w3.org/2000/svg"><path d="m61 11h-58a1 1 0 0 0 -1 1v9h60v-9a1 1 0 0 0 -1-1zm-54 7a2 2 0 1 1 2-2 2.006 2.006 0 0 1 -2 2zm7 0a2 2 0 1 1 2-2 2.006 2.006 0 0 1 -2 2zm7 0a2 2 0 1 1 2-2 2.006 2.006 0 0 1 -2 2z" fill="#57a4ff"/><g fill="#004fac"><path d="m61 10h-58a2.006 2.006 0 0 0 -2 2v40a2.006 2.006 0 0 0 2 2h58a2.006 2.006 0 0 0 2-2v-40a2.006 2.006 0 0 0 -2-2zm-58 2h58v8h-58zm58 40h-58v-30h58z"/><path d="m7 13a3 3 0 1 0 3 3 3.009 3.009 0 0 0 -3-3zm0 4a1 1 0 1 1 1-1 1 1 0 0 1 -1 1z"/><path d="m14 13a3 3 0 1 0 3 3 3.009 3.009 0 0 0 -3-3zm0 4a1 1 0 1 1 1-1 1 1 0 0 1 -1 1z"/><path d="m21 13a3 3 0 1 0 3 3 3.009 3.009 0 0 0 -3-3zm0 4a1 1 0 1 1 1-1 1 1 0 0 1 -1 1z"/><path d="m46 50h8a1 1 0 0 0 0-2h-8a1 1 0 0 0 0 2z"/><path d="m57 50h1a1 1 0 0 0 0-2h-1a1 1 0 0 0 0 2z"/><path d="m45 25v10a1 1 0 0 1 -2 0v-7.59l-20.59 20.59h7.59a1 1 0 0 1 0 2h-10a1 1 0 0 1 -.38-.08.956.956 0 0 1 -.54-.54 1 1 0 0 1 -.08-.38v-10a1 1 0 0 1 2 0v7.59l20.59-20.59h-7.59a1 1 0 0 1 0-2h10a1 1 0 0 1 .38.08.956.956 0 0 1 .54.54 1 1 0 0 1 .08.38z"/></g></svg>
  <p>- Resize browser to change video source</p>
</div>

<div class="video-container">
  <video autoplay muted playsinline loop class="responsive-video"
    data-video-src-sm="https://ak.picdn.net/shutterstock/videos/30708286/preview/stock-footage-t-l-ws-smooth-lake-and-alps-in-distance-kitzbueheler-austria.mp4"
    data-video-src-md="https://ak.picdn.net/shutterstock/videos/10851212/preview/stock-footage-mt-shasta-mountain-siskiyou-lake-bridge-california-recreation-landscape.mp4"
    data-video-src-lg="https://ak.picdn.net/shutterstock/videos/18667577/preview/stock-footage-aerial-footage-of-glenorchy-new-zealand-in-winter-lord-of-the-rings-film-location-middle-earth.mp4">
  </video>
</div>

<ul class="social">
  <li>
    <a href="https://codepen.io/rhyspacker/" class="icon codepen" title="CodePen" target="_blank">
      <svg viewBox="0 0 512 512">
        <path d="M427 201.9c-0.6-4.2-2.9-8-6.4-10.3L264.2 87.3c-4.9-3.3-11.4-3.3-16.3 
                 0L91.4 191.6c-4 2.7-6.5 7.4-6.5 12.2v104.3c0 4.8 2.5 9.6 6.5 12.2l156.4 104.3c4.9 
                 3.3 11.4 3.3 16.3 0L420.6 320.4c4-2.6 6.6-7.4 6.6-12.2V203.9C427.1 203.2 
                 427.1 202.6 427 201.9 427 201.7 427.1 202.6 427 201.9zM270.7 127.1l115.2 76.8 
                 -51.5 34.4 -63.8-42.7V127.1zM241.3 127.1v68.6l-63.8 42.7 -51.5-34.4L241.3 
                 127.1zM114.3 231.4l36.8 24.6 -36.8 24.6V231.4zM241.3 384.9L126.1 308.1l51.5-34.4 
                 63.8 42.6V384.9zM256 290.8l-52-34.8 52-34.8 52 34.8L256 290.8zM270.7 
                 384.9V316.3l63.8-42.6 51.5 34.4L270.7 384.9zM397.7 280.6l-36.8-24.6 
                 36.8-24.6V280.6z"/>
      </svg>
      <!--[if lt IE 9]><em>CodePen</em><![endif]-->
    </a>
  </li>
  <li>
    <a href="https://github.com/Rhyspacker" class="icon github" title="GitHub" target="_blank">
      <svg viewBox="0 0 512 512">
        <path d="M256 70.7c-102.6 0-185.9 83.2-185.9 185.9 0 82.1 53.3 151.8 127.1 176.4 
                 9.3 1.7 12.3-4 12.3-8.9V389.4c-51.7 11.3-62.5-21.9-62.5-21.9 -8.4-21.5-20.6-27.2-20.6-27.2 
                 -16.9-11.5 1.3-11.3 1.3-11.3 18.7 1.3 28.5 19.2 28.5 19.2 16.6 28.4 43.5 20.2 54.1 
                 15.4 1.7-12 6.5-20.2 11.8-24.9 -41.3-4.7-84.7-20.6-84.7-91.9 0-20.3 7.3-36.9 
                 19.2-49.9 -1.9-4.7-8.3-23.6 1.8-49.2 0 0 15.6-5 51.1 19.1 14.8-4.1 30.7-6.2 
                 46.5-6.3 15.8 0.1 31.7 2.1 46.6 6.3 35.5-24 51.1-19.1 51.1-19.1 10.1 25.6 3.8 44.5 
                 1.8 49.2 11.9 13 19.1 29.6 19.1 49.9 0 71.4-43.5 87.1-84.9 91.7 6.7 5.8 12.8 17.1 
                 12.8 34.4 0 24.9 0 44.9 0 51 0 4.9 3 10.7 12.4 8.9 73.8-24.6 127-94.3 
                 127-176.4C441.9 153.9 358.6 70.7 256 70.7z"/>
      </svg>
      <!--[if lt IE 9]><em>GitHub</em><![endif]-->
    </a>
  </li>
  <li>
    <a href="https://www.linkedin.com/in/rhyspacker/" class="icon linkedin" title="LinkedIn"  target="_blank">
      <svg viewBox="0 0 512 512">
        <path d="M186.4 142.4c0 19-15.3 34.5-34.2 34.5 -18.9 0-34.2-15.4-34.2-34.5 0-19 
                 15.3-34.5 34.2-34.5C171.1 107.9 186.4 123.4 186.4 142.4zM181.4 201.3h-57.8V388.1h57.8V201.3zM273.8 
                 201.3h-55.4V388.1h55.4c0 0 0-69.3 0-98 0-26.3 12.1-41.9 35.2-41.9 21.3 0 31.5 15 
                 31.5 41.9 0 26.9 0 98 0 98h57.5c0 0 0-68.2 0-118.3 0-50-28.3-74.2-68-74.2 -39.6 
                 0-56.3 30.9-56.3 30.9v-25.2H273.8z"/>
      </svg>
      <!--[if lt IE 9]><em>LinkedIn</em><![endif]-->
    </a>
  </li>
  
  <li>
    <a href="https://twitter.com/Rhyspacker" class="icon twitter" title="Twitter" target="_blank">
      <svg viewBox="0 0 512 512">
        <path d="M419.6 168.6c-11.7 5.2-24.2 8.7-37.4 10.2 13.4-8.1 23.8-20.8 28.6-36 
                 -12.6 7.5-26.5 12.9-41.3 15.8 -11.9-12.6-28.8-20.6-47.5-20.6 -42 0-72.9 39.2-63.4 
                 79.9 -54.1-2.7-102.1-28.6-134.2-68 -17 29.2-8.8 67.5 20.1 86.9 
                 -10.7-0.3-20.7-3.3-29.5-8.1 -0.7 30.2 20.9 58.4 52.2 64.6 -9.2 2.5-19.2 3.1-29.4 
                 1.1 8.3 25.9 32.3 44.7 60.8 45.2 -27.4 21.4-61.8 31-96.4 27 28.8 18.5 63 29.2 99.8 
                 29.2 120.8 0 189.1-102.1 185-193.6C399.9 193.1 410.9 181.7 419.6 168.6z"/>
      </svg>
      <!--[if lt IE 9]><em>Twitter</em><![endif]-->
    </a>
  </li>
</ul>
              
            
!

CSS

              
                // ==============================
// Video 
// ========================================

.video-container {
  max-width: 1200px;
  margin: 0 auto 100px auto;
  padding: 0 20px;
  
  video {
    width: 100%;
  }
}

// ==============================
// Tip
// ========================================

.tip {
  max-width: 1200px;
  margin: 40px auto 40px auto;
  
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: arial;
  font-weight: bold;
  
  svg {
    margin-right: 10px;
  }
}

// ==============================
// Social
// ========================================

.social {
  position: fixed;
  bottom: 20px;
  right: 0;
  font-size: 0;
  list-style: none; 
  margin: 0;
  padding: 0 26px;
  
  li {
    display: inline-block;
    margin: 12px;
  }
  
  a, svg {
    display: block;
  }
  
  a { 
    position: relative;
    height: 40px;
    width: 40px;
  }
  
  svg {
    height: 100%;
    width: 100%;
  }
  
  .icon {
    color: #444757;
    fill: #444757;
    &:hover {
      border-radius: 100%;
      
      color: #5f637a;
      fill: #5f637a;
      
      -webkit-transform: scale(1.25);

      transform: scale(1.25);

      -webkit-transition: background-color 0.5s, 
      -webkit-transform 0.5s ease-out;

      transition: background-color 0.5s, 
      -webkit-transform 0.5s ease-out;

      transition: background-color 0.5s, 
      transform 0.5s ease-out;

      transition: background-color 0.5s, 
      transform 0.5s ease-out, 
      -webkit-transform 0.5s ease-out;
    }
  }
}
              
            
!

JS

              
                //##########################################################################
// Responsive video
//##########################################################################

var app = {
  debounce: function(func, wait = 100) {
    let timeout;
    return function(...args) {
      clearTimeout(timeout);
      timeout = setTimeout(() => {
        func.apply(this, args);
      }, wait);
    };
  }
};

app.responsiveVideo = {
  responsiveVideos: null,

  breakpoints: {
    tablet: 768,
    desktop: 1024
  },

  init: function() {
    var self = this;

    // Set local elements
    self.responsiveVideos = $('.responsive-video');

    if ( self.responsiveVideos.length ) {
      self.responsiveVideos.each(function(index, responsiveVideo) {
        self.handleVideoSource(responsiveVideo);
      })

      self.handleResize();
    }
  },

  handleVideoSource: function(responsiveVideo) {
    var self = this;

    var video = $(responsiveVideo);

    // Initialise the first load to set video.data('isMobile')/isTablet/isDesktop values
    //
    if ( !video.data('data-init') ) {

      // If tablet or less
      if ( $(window).width() <= self.breakpoints.tablet ) {
        if ( video.attr("data-video-src-sm") !== undefined ) {
          self.setSmallVideoSource(video);
        } else {
          self.setLargeVideoSource(video);
        }
      }
      // If above tablet and less than desktop
      else if ( $(window).width() > self.breakpoints.tablet && $(window).width() < self.breakpoints.desktop ) {
        if ( video.attr("data-video-src-md") !== undefined ) {
          self.setMediumVideoSource(video);
        } else {
          self.setLargeVideoSource(video);
        }
      }
      // If above desktop
      else if ( $(window).width() >= self.breakpoints.desktop ) {
        self.setLargeVideoSource(video);
      }

      video.data('data-init', true);
    } else {
      // This block is triggered on resize
      //
      // Use of video.data('isMobile')/isTablet/isDesktop prevents multiple <source> updates (when resizing)
      // Instead will only update at each breakpoint - not each resize event.
      //
      // Adds sources to video based on screen size,
      // from data-video-src-sm/data-video-src-md/data-video-src-lg
      // If sm/md sizes aren't defined it will default to lg
      //
      // If tablet or less
      if ( $(window).width() <= self.breakpoints.tablet && video.data('isMobile') === false ) {
        if ( video.attr("data-video-src-sm") !== undefined ) {
          self.setSmallVideoSource(video);
        } else {
          self.setLargeVideoSource(video);
        }
      }
      // If above tablet and less than desktop
      else if ( $(window).width() > self.breakpoints.tablet && $(window).width() < self.breakpoints.desktop && video.data('isTablet') === false ) {
        if ( video.attr("data-video-src-md") !== undefined ) {
          self.setMediumVideoSource(video);
        } else {
          self.setLargeVideoSource(video);
        }
      }
      // If above desktop
      else if ( $(window).width() >= self.breakpoints.desktop && video.data('isDesktop') === false  ) {
        self.setLargeVideoSource(video);
      }

    }

  },

  setLargeVideoSource: function(video) {
    var self = this;

    // Create source for .mp4
    //
    var source = `<source src='${video.data("video-src-lg")}' type='video/mp4'>`;

    // Reload the video with new source
    //
    video.html(source);
    video.get(0).load();
    video.get(0).play();

    // Set screen size state of this video
    //
    video.data('isMobile', false);
    video.data('isTablet', false);
    video.data('isDesktop', true);
  },

  setMediumVideoSource: function(video) {
    var self = this;

    // Create source for .mp4
    //
    var source = `<source src='${video.data("video-src-md")}' type='video/mp4'>`;

    // Reload the video with new source
    //
    video.html(source);
    video.get(0).load();
    video.get(0).play();

    // Set screen size state of this video
    //
    video.data('isMobile', false);
    video.data('isTablet', true);
    video.data('isDesktop', false);
  },

  setSmallVideoSource: function(video) {
    var self = this;

    // Create source for .mp4
    //
    var source = `<source src='${video.data("video-src-sm")}' type='video/mp4'>`;

    // Reload the video with new source
    //
    video.html(source);
    video.get(0).load();
    video.get(0).play();

    // Set screen size state of this video
    //
    video.data('isMobile', true);
    video.data('isTablet', false);
    video.data('isDesktop', false);
  },

  handleResize: function() {
    var self = this;

    self.responsiveVideos.each(function(index, responsiveVideo) {

      var width = $(window).width();

      window.addEventListener("resize", app.debounce(function() {
        if ( $(this).width() != width ) {
          width = $(this).width();

          self.handleVideoSource(responsiveVideo);
        }
      }, 500));

    });
  }
};

$(document).ready(function() {
  app.responsiveVideo.init();
})

              
            
!
999px

Console