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

              
                <section>
    <div style="min-width: 250px">
        <p>x-component:</p>
        <x-component>
            <span slot="one">Light DOM: span 1</span>
            <span slot="two">Light DOM: span 2</span>
            <span slot="one">Light DOM: span 3</span>
            <span slot="two">Light DOM: span 4</span>
            <span>Light DOM: span 5</span>
        </x-component>
    </div>
    <div>
        <p>Styles being applied by the component:</p>
        <div>
            <pre class="language-css line-numbers"><code id="styles">::slotted(*:first-child) {
  color: red;
}
::slotted(*:last-child) {
  color: blue;
}</code></pre>
            <pre class="language-css line-numbers"><code id="styles">::slotted([slot="one"]:first-child) {
  text-decoration: underline orange;
}
::slotted([slot="one"]:last-child) {
  text-decoration: underline yellow;
}</code></pre>
            <pre class="language-css line-numbers"><code id="styles">::slotted([slot="two"]:first-child) {
  text-decoration: underline green;
}
::slotted([slot="two"]:last-child) {
  text-decoration: underline purple;
}</code></pre>
        </div>
    </div>
</section>
              
            
!

CSS

              
                body {
    font-size: 16px;
    font-family: sans-serif;
    margin: 20px;
}

p {
    display: inline-block;
}

x-component {
    font-size: 1.5em;
}

pre {
    padding-right: 2rem !important;
}

section {
    display: flex;
    flex-flow: row nowrap;
    gap: 6rem;
    justify-content: center;
}

div > div {
    display: flex;
    flex-flow: row wrap;
    gap: 2rem;
    align-items: flex-start;
    justify-content: flex-start;
}

@media screen and (max-width: 850px) {
    body {
        font-size: 14px;
    }

    section {
        flex-wrap: wrap;
        gap: 2rem;
        align-items: flex-start;
        // justify-content: flex-start;
    }
    div > div {
        gap: 1rem;
        width: min-content;
    }
}

              
            
!

JS

              
                import { html, css, LitElement } from "https://cdn.skypack.dev/lit";
import {
    customElement,
    property
} from "https://cdn.skypack.dev/lit/decorators.js";

import PfeCodeblock from "https://unpkg.com/@patternfly/pfe-codeblock?module";

@customElement("x-component")
export class XComponent extends LitElement {
    static styles = css`
        :host {
            display: flex;
            flex-flow: column nowrap;
            padding: 2rem;
            background: #f5f2f0;
            max-width: max-content !important;
        }
        h3 {
            margin-top: 2rem;
            margin-bottom: 0.4rem;
            font-size: 0.6em;
            font-weight: 100;
            text-transform: uppercase;
        }
        h3:first-child {
            margin-top: 0;
        }
        slot {
            display: flex;
            flex-flow: column nowrap;
            gap: 0.3rem;
            background: white;
            padding: 0.5rem;
            outline: 1px solid black;
        }
        slot[name="one"] {
            outline: 1px solid gray;
        }
        slot[name="two"] {
            outline: 1px solid lightgray;
        }
        ::slotted(*:first-child) {
            color: red;
        }
        ::slotted(*:last-child) {
            color: blue;
        }
        ::slotted([slot="one"]:first-child) {
            text-decoration: underline orange;
        }
        ::slotted([slot="one"]:last-child) {
            text-decoration: underline yellow;
        }
        ::slotted([slot="two"]:first-child) {
            text-decoration: underline green;
        }
        ::slotted([slot="two"]:last-child) {
            text-decoration: underline purple;
        }
    `;

    render() {
        return html`
            <h3>Default slot</h3>
            <slot></slot>
            <h3>Slot one</h3>
            <slot name="one"></slot>
            <h3>Slot two</h3>
            <slot name="two"></slot>
        `;
    }
}

              
            
!
999px

Console