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.

              <!-- The template used for the custom element -->
<template id="user-comment-template">
  <!-- Styles will be scoped inside the shadow DOM -->
    .container {
      align-items: center;
      display: flex;
      max-width: 100%;
      padding: 0.5rem;
    .avatar-container {
      background: lightgray;
      border-radius: 100%;
      height: 3rem;
      margin-right: 0.5rem;
      overflow: hidden;
      width: 3rem;
    /* Style the image directly - either the slotted one or the default */
    slot[name="avatar"]::slotted(img), slot[name="avatar"] img, {
      max-width: 100%;
    slot[name="username"], slot[name="comment"] {
      display: block;
    slot[name="username"] {
      font-weight: bold;
      margin-bottom: 0.25rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    .comment {
      flex: 1;
      min-width: 0;
    .unknown {
      opacity: 0.5;
  <!-- The contents of the web component -->
  <div class="container">
    <div class="avatar-container">
      <slot name="avatar">
        <!-- Placeholder content when there is no data for the slot -->
        <img alt="" src="https://picsum.photos/g/100?random" />
    <div class="comment">
      <slot name="username">
        <!-- Placeholder content when there is no data for the slot -->
        <span class="unknown">No name</span>
      <slot name="comment">
        <!-- Placeholder content when there is no data for the slot -->
        <span class="unknown">This user did not leave a comment</span>

<!-- How to use the new user-comment element -->
  <img alt="" slot="avatar" src="https://picsum.photos/100?random" />
  <span slot="username">Matt Crouch</span>
  <div slot="comment">This is an example of a comment a user might leave</div>

<!-- What happens if the developer does not pass values to a slot -->
  <!-- Default values -->
              @import url("https://fonts.googleapis.com/css?family=Roboto:400,700");

* {
  box-sizing: border-box;

html {
  font-family: Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  font-smooth: always;
  -webkit-font-smoothing: antialiased;
  line-height: 1.25;

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 auto;
  min-height: 100vh;
  width: 66%;
              // Create a new UserComment element
class UserComment extends HTMLElement {
  constructor() {
    // Create an open shadow DOM that this component can use
    this.attachShadow({ mode: "open" });
  // What to do when the component gets connected
  connectedCallback() {
    // Find the required template
    const template = document.getElementById("user-comment-template");
    // Copy the template content
    const node = document.importNode(template.content, true);
    // Apply it to the shadow DOM

// Tell the browser that the `user-comment` element should use this component class
customElements.define("user-comment", UserComment);
🕑 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.