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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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="embedWrapper">
  <div class="embed">
    <div data-youtube-id="PSX2iTnN4hg"></div>
  </div>
</div>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
  proident, sunt in culpa qui officia deserunt mollit anim id est .</p>

  <div class="embed">
    <div data-youtube-id="__j5Z_WcVgE"></div>
  </div>
              
            
!

CSS

              
                .embedWrapper {
  // it needs another wrapper because otherwise the padding will be relative to 100% width, not to max-width
  // if the video needs to fit full width of it's parent, this element is useless.
  max-width:640px;
}

.embed {
  position:relative;
  height:0;
  overflow:hidden;
  padding-top:56%; // if the video have a different ratio than 16:9 you may want to fiddle with this a bit
}

.embed div {
  position:absolute;
  left:0;
  top:0;
  width:100%;
  height:100%;
  background:#c00;
}
              
            
!

JS

              
                ;(function( $, document ){
  /*
    <div class="item-type-video" data-youtube-id="YOUTUBE-VIDEO-ID"></div>
   */
  if (!Object.create) { Object.create = function (o) { if (arguments.length > 1) { throw new Error('Object.create implementation only accepts the first parameter.'); } function F() {} F.prototype = o; return new F(); }; }

  var youtubeTag = document.createElement('script');
  youtubeTag.src = "//www.youtube.com/iframe_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(youtubeTag, firstScriptTag);

  var ntzYoutubeEmbed = {
    init: function( el ){
      var $this = this;
      $this.el = $( el );

      var ytTimer = window.setInterval(function(){
        if( typeof YT == 'object' && typeof YT.Player == 'function' ){
          window.clearInterval( ytTimer );
          $this.YTApiReady();
        }
      }, 10);
    } // init


    ,YTApiReady: function(){
      var $this = this;
      this.movieContainerID = 'video-' + Math.round( Math.random() * 1000000 );

      $('<div class="youtube-iframe" />').attr({
        'id': this.movieContainerID
      }).appendTo( $this.el );

      $this.createPlayer();
      
      this.el.on('player-pause', function(){ $this.player.pauseVideo(); });
      this.el.on('player-stop', function(){ $this.player.seekTo(0); $this.player.stopVideo(); });
      this.el.on('player-play', function(){ $this.player.playVideo(); });

      this.el.on('player-toggle-state', function(){
        var player = $this.player,
            state = player.getPlayerState();

        if( state == 1 ){
          player.pauseVideo();
        }

        if( state == 2 ){
          player.playVideo();
        }
      });
    }//YTApiReady


    ,createPlayer: function(){
      var $this = this;

      var playerVars = $.extend({
          enablejsapi   : 1,
          autohide      : 2,
          iv_load_policy: 3,
          modestbranding: true,
          origin        : window.location.origin,
          rel           : 0,
          showinfo      : 0,
          theme         : 'light',
          color         : 'white',
          controls      : 0,
          autoplay      : 0,
          poster        : ""
        }, $this.el.data() );

      if( playerVars.poster ){
        var poster = $('<img class="player-poster" />').attr('src', playerVars.poster );
        poster.appendTo( $this.el );
        $this.el.addClass('player-has-poster');
        poster.on('click', function(){
          $(this).addClass('is-playing');
          $this.el.trigger('player-play');
        });
      }

      this.player = new YT.Player( this.movieContainerID, {
        height    : '100%',
        width     : '100%',
        videoId   : this.el.data('youtube-id'),
        playerVars: playerVars,
        events    : {
          'onReady'      : $.proxy( $this.movieReady, $this ),
          'onStateChange': $.proxy( $this.stateChange, $this )
        }
      });
    }//createPlayer


    ,movieReady: function( player ){
      this.el.data('youtubePlayer', player.target ).trigger( 'player-ready', player );
    }//movieReady


    ,stateChange: function( state ){
      this.el.data('video-state', state).trigger('player-state-change', state);
    }//stateChange
  };


  $.fn.ntzYoutubeEmbed = function() {
    return this.each(function(){
      var obj = Object.create( ntzYoutubeEmbed );
      obj.init( this );
    });
  };
})( jQuery, document );

jQuery(document).ready(function($){
  $('div[data-youtube-id]').ntzYoutubeEmbed(); // optional
});
              
            
!
999px

Console