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

              
                <p class="my-p">Light DOM on a page</p>
<my-component>
  <p>Light DOM inside WC slot: Shadow DOM CSS told me to be underlined</p>
</my-component>

<template id="my-component">
  <!-- This is shared CSS that you can include in every component -->
  <link rel="stylesheet" href="https://codepen.io/stylet/pen/QXYwbW.css">
  <style>
    :host {
      display: block;
    }
    p::after { /* Affects Shadow DOM only */
      color: black;
      border: 1px solid black;
      margin-left: 5px;
      content: "(I'm Shadow DOM CSS)"
    }
    
    ::slotted(p) { /* Affects slot content within Shadow DOM only */
      text-decoration: underline;
    }
    
    /* Doesn't work in Safari */
    ::slotted(p)::before { /* Affects slot content within Shadow DOM only */
      color: black;
      border: 1px solid black;
      margin-right: 5px;
      content: "(I'm Shadow DOM CSS for slot content)"
    }
  </style>
  <p>Shadow DOM: I inherited red color from &lt;html&gt; element</p>
  <slot></slot>
</template>

              
            
!

CSS

              
                p::after { /* Affects Light DOM only */
  color: black;
  border: 1px solid black;
  margin-left: 5px;
  content: "(I'm Light DOM CSS)"
}
html {
  color: green; /* Affects Light and Shadow DOM because color is inherited property */
}
              
            
!

JS

              
                'use strict';

const template = document.getElementById('my-component');

class MyContext extends HTMLElement {
  constructor() {
    super();
    
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.appendChild(template.content.cloneNode(true));
  };
};

customElements.define('my-component', MyContext);

              
            
!
999px

Console