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.


                <h1>One-click play+fullscreen via YouTube API</h1>
Suggested code from this <a href="">StackOverflow answer</a>

  <li>Click on [play fullscreen]</li>
  <li>Click on the fullscreen button in youtube's player to exit fullscreen</li>

<script src=""></script>
<button>play fullscreen</button><br>
<div id="player"></div>

## Safari 8

It works perfectly:

0. Enters fullscreen
0. Exits fullscreen

## Firefox 35

Buggy, annoying but working:

0. Enters fullscreen (on
0. Enters fullscreen (
0. Third click: Exits fullscreen

## Chrome 40

Buggy, broken:

0. Enters fullscreen (on
0. Does nothing
0. Third click: Exits fullscreen but the video fills the iframe, effectively breaking the site. <a href="" target="_blank">Screenshot</a>

## Mobile browsers

This is the default behavior on iPhone, but it cannot work anywhere else (Android, iPad) since 

* to `play()` a video or to `requestFullScreen()` you need a user tap **in the same document** (read: not across the iframe)

This means that

* you can't call `requestFullScreen()` when the video emits the event `onplay`
* you can't trigger `play()` via YouTube API (it would cross the frame) **and** call `requestFullScreen()` in the same tap

So with one tap **either** you play the video **or** get it fullscreen; you'll always need two separate taps if you use YouTube.



                html {
  padding: 1em;
button {
  width: 200px;
  height: 100px;
  margin-bottom: 1em;


                var player, iframe;
var $ = document.querySelector.bind(document);

// init player
function onYouTubeIframeAPIReady() {
  player = new YT.Player('player', {
    height: '200',
    width: '300',
    videoId: 'dQw4w9WgXcQ',
    events: {
      'onReady': onPlayerReady

// when ready, wait for clicks
function onPlayerReady(event) {
  var player =;
  iframe = $('#player');

function setupListener (){
$('button').addEventListener('click', playFullscreen);

function playFullscreen (){
  player.playVideo();//won't work on mobile
  var requestFullScreen = iframe.requestFullScreen || iframe.mozRequestFullScreen || iframe.webkitRequestFullScreen;
  if (requestFullScreen) {