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

              
                <h1>Improving Web Font Performance with Local Storage (Demo)</h1>

<p>I am speaking on literary criticism, and in the world in which we are actually living that is almost as unpromising as speaking about peace. This is not a peaceful age, and it is not a critical age. In the Europe of the last ten years literary criticism of the older kind — criticism that is really judicious, scrupulous, fair-minded, treating a work of art as a thing of value in itself — has been next door to impossible.</p>

<p class="p">Demo by Luis Vieira. <a href="http://www.sitepoint.com/improving-font-performance-subsetting-local-storage/" target="_blank">See article</a> (publishing April 7, 2015).</p>
              
            
!

CSS

              
                body {
  text-align: center;
  line-height: 1.5;
  padding: 0 30px;
}

.fallback {
  font-family: 'Georgia', serif;
  line-height: 1.7em;
  letter-spacing: 1px;
  font-size: 15px;
}

.webFont {
  font-family: 'vollkornregular', serif;
  line-height: 1.6em;
  letter-spacing: 1px;
  font-size: 16px;
}

p {
  text-align: left;
}

.p {
  padding-top: 100px;
  text-align: center;
  font-size: 14px;
}
              
            
!

JS

              
                (function () {
  'use strict';
  document.documentElement.className = 'fallback';
  var css_href = 'https://codepen.io/SitePoint/pen/6c6dc49b39b410083cd30ac1f16be2fa.css';
  var localStorageSupported = function() {
    try {
      localStorage.setItem('test', 'test');
      localStorage.removeItem('test');
      return true;
    } catch(e) {
      return false;
    }
  }

  if (localStorageSupported() && localStorage.spdemowebFonts) {
    injectRawStyle(localStorage.getItem('spdemowebFonts'));
  } else {
    window.onload = function() {
      injectFontsStylesheet();
    }
  }

  function injectFontsStylesheet() {
    var xhr = new XMLHttpRequest();
      xhr.open('GET', css_href, true);
      xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
          injectRawStyle(xhr.responseText);
          localStorage.setItem('spdemowebFonts', xhr.responseText);
        }
      }
    xhr.send();
  }

  function injectRawStyle(text) {
    var style = document.createElement('style');
    style.innerHTML = text;
    document.getElementsByTagName('head')[0].appendChild(style);
    document.documentElement.className = 'webFont';
  }
}());
              
            
!
999px

Console