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

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

              
                <!-- Check out head settings by clicking the cog icon next to the HTML window -->

<body class="no-js">
  <p>
    <button onClick="loadFontCSS()">
  Load Font CSS - initiate font file download
    </button></p>
  
  <p>
    Font: <span id="js-font-status">not loaded</span>
  </p>
  
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus pulvinar nulla. Proin vitae ex vitae eros ultricies placerat. Vivamus consectetur ultrices vulputate. Curabitur sit amet scelerisque tortor, nec eleifend dolor. Vestibulum justo arcu, volutpat vel fermentum et, tempus vulputate metus.</>
  
  
  <!-- Let's visibly hide this element and make screen readers ignore it. We need this element to check if the font is loaded. -->
      <div aria-visibility="hidden" class="hidden" style="font-family: 'Merriweather'">&nbsp;</div>
  
  
  <script>
    /* If JavaScript is not available, 
     * you can use .no-js class to apply
     * web font styles.
     *
     * If JS is available, 
     * this class will be removed.    
     */
    document.getElementsByTagName("body")[0].classList.remove("no-js");
  </script>
  
</body>
              
            
!

CSS

              
                body {
    font-size: 24px;
  line-height: 1.5;
}

.wf-merriweather--loaded,
.no-js {
  font-family: "Merriweather";
}

body:not(.wf-merriweather--loaded):not(.no-js) {
    font-family: Georgia, serif;
letter-spacing: 1.3px;
  font-size: 24px;
}

.hidden {
  position: absolute; 
  overflow: hidden; 
  clip: rect(0 0 0 0); 
  height: 1px; width: 1px; 
  margin: -1px; padding: 0; border: 0; 
}


/* Unrelated styles - formatting */

body {
  max-width: 568px;
  margin: 0 auto;
  padding: 1em;
}

p {
  margin-bottom: 1em;
}
              
            
!

JS

              
                let interval = null;

function fontLoadListener() {
  var hasLoaded = false
      /* 
       * If anything goes wrong with the font loading API, 
       * just change styles to the web font without handling FOUT 
       */
      try {
        hasLoaded = document.fonts.check('12px "Merriweather"')
      } catch (error) {
        console.info(`document.fonts API error: ${error}`)
        fontLoadedSuccess();
        return
      }
  
  if(hasLoaded) {
    fontLoadedSuccess();
  }
}

function fontLoadedSuccess() {
  if(interval) {
    clearInterval(interval);
  }
  
  document.getElementById("js-font-status").innerHTML = "finished loading";
  document.getElementsByTagName("body")[0].classList.add("wf-merriweather--loaded");
}

/*
 * We'll start the interval on button click so 
 * we don't run it all the time in the background 
 * when no loading is happening. 
 * You can uncomment the line on your project.
 *
 * interval = setInterval(fontLoadListener, 500)
 */

/* Button click code - not relevant to the example */

function loadFontCSS() {
  interval = setInterval(fontLoadListener, 500)
  var link = document.createElement("link");
  link.rel = "stylesheet";
  link.href="https://fonts.googleapis.com/css2?family=Merriweather&display=swap";
  
  document.getElementsByTagName("head")[0].appendChild(link);
}
              
            
!
999px

Console