Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

    <h1>Fallback, "light DOM" content</h1>
    <p>This content will live in a slot element. We'll make paragraphs look different if web components are supported.</p>
              :root {
    --button-bg: #2c3e50;

body {
    padding: 2rem;
    font-family: sans-serif;
    line-height: 1.4;

h1 {
    line-height: 1.1;

first-component {
    display: block;
    max-width: 60ch;

              // First, create the class that defines our custom element
class FirstComponent extends HTMLElement {
    constructor() {
        this.buttonText = 'Oh hey, click me for a party';
        // Create and attach a shadow root
        this._shadowRoot = this.attachShadow({ mode: 'open' });
    render() {
        this._shadowRoot.innerHTML = `

                /* Button styles from "Button Pal" https://codepen.io/hankchizljaw/pen/Vxpjvo */
                button {
                    display: inline-block;
                    border: none;
                    padding: 1rem 2rem;
                    margin: 0;
                    text-decoration: none;
                    /* Custom props allow us to style from the outside too */
                    background: var(--button-bg, #0069ed);

                    color: #ffffff;
                    font-family: sans-serif;
                    font-size: 1rem;
                    cursor: pointer;
                    text-align: center;
                    transition: background 250ms ease-in-out, 
                                transform 150ms ease;
                    -webkit-appearance: none;
                    -moz-appearance: none;

                button:focus {
                    background: #0053ba;

                button:focus {
                    outline: 1px solid #fff;
                    outline-offset: -4px;

                button:active {
                    transform: scale(0.99);

                /* Make paragraphs italic, red and bigger */
                ::slotted(p) {
                    font-style: italic;
                    font-weight: 500;
                    color: #c0392b;
                    font-size: 1.2rem;
    bindEvents() {
        // We couldn't access this button via the `document` which is cool
        this._shadowRoot.querySelector('button').addEventListener('click', (evt) => {

customElements.define('first-component', FirstComponent);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.