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

              
                <emerald-counter current-count=7>
</emerald-counter>

<div>
  <p style="max-width: 65ch">An experiment in creating a re-usable web component for a notification indicator with a counter.  The biggest disappointment in this experiment was discovering that the SVG component does not respond to the <kbd>::part()</kbd> selector, so it's not possible
    to change the color of the SVG component without providing some hacky extra property
    on the element itself.
  </p>
  <p style="max-width: 65ch">Of note here is the <kbd>::root</kbd> declaration in the CSS.  That specifies 
  a size between 12px and 48px, depending on how wide your viewport is.  If you resize the browser window (or just <kbd>inspect</kbd> to get a slideable resizable viewport), you can play with the viewport size and watch the component scale smoothly from "10 foot display" all the way down to "looks good on your phone" size.</p>
</div>
              
            
!

CSS

              
                    body {
      background: #fafafa;
    }
   :root {
       --step-0: clamp(0.75rem, 0.491rem + 1.295vw, 3rem);
   }
   emerald-counter {
       width: calc(var(--step-0) * 4);
       font-size: calc(var(--step-0) * 4);
   }
   emerald-counter::part(counter) {
       background-color: green;
   }
   emerald-counter::part(number) {
       color: yellow;
   }
   emerand-counter::part(bell) {
       fill: navy;
       stroke: navy;
   }

              
            
!

JS

              
                import {
  html,
  css,
  LitElement
} from "https://cdn.skypack.dev/lit@2.0.0-rc.2?dts";

import {
  customElement,
  property,
  state
} from "https://cdn.skypack.dev/lit@2.0.0-rc.2/decorators.js";

@customElement("emerald-counter")
class EmeraldCounter extends LitElement {
    static styles = css`
        :host {
            display: inline-block;
            aspect-ratio: 1 / 1;
        }

        div#main {
            position: relative;
            display: block;
            width: 100%;
            height: 100%;
        }

        svg {
            position: relative;
            display: block;
            width: 100%;
            height: 100%;
            z-index: 0;
        }

        div#counter {
            display: grid;
            justify-content: center;
            align-content: center;
            position: absolute;
            z-index: 1;
            font-family: "Helvetica Neue", "Arial Nova", Helvetica, Arial, sans-serif;
            font-size: 0.25em;
            top: 8%;
            left: 60%;
            width: 30%;
            height: 30%;
            aspect-ratio: 1 / 1;
            border-radius: 50%;
            border: 0.2em solid white;
            font-weight: bold;
            background: red;
            color: white;
        }

        div#counter span {
            padding-top: 0.1em;
            vertical-align: text-bottom;
        }
    `;

    @property({ type: Number, attribute: "current-count" })
    counter = 0;

    render() {
        return html`
            <div id="main">
                <svg
                    id="Layer_1"
                    version="1.1"
                    viewBox="0 0 512 512"
                    xml:space="preserve"
                    xmlns="http://www.w3.org/2000/svg"
                    xmlns:xlink="http://www.w3.org/1999/xlink"
                    part="bell"
                >
                    <g>
                        <path
                            part="bell"
                            d="M381.7,225.9c0-97.6-52.5-130.8-101.6-138.2c0-0.5,0.1-1,0.1-1.6c0-12.3-10.9-22.1-24.2-22.1c-13.3,0-23.8,9.8-23.8,22.1   c0,0.6,0,1.1,0.1,1.6c-49.2,7.5-102,40.8-102,138.4c0,113.8-28.3,126-66.3,158h384C410.2,352,381.7,339.7,381.7,225.9z"
                        />
                        <path
                            part="bell"
                            d="M256.2,448c26.8,0,48.8-19.9,51.7-43H204.5C207.3,428.1,229.4,448,256.2,448z"
                        />
                    </g>
                </svg>
                ${!this.counter || this.counter < 1
                    ? nothing
                    : html`<div id="counter" part="counter"><span part="number">${this.counter}</span></div>`}
            </div>
        `;
    }
}

              
            
!
999px

Console