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

              
                <template id="template">
  <style>
    :host {
      --text-color: white;
      --background-color: red;
      --background-color-hover: darkred;
      --display: block;
      --width: 100%;
      --border-radius: 2px;
      --box-shadow: none;
    }

    .button {
      display: var(--display);
      width: var(--width);
      margin-bottom: 5px;
      padding: 1rem 1.5rem;
      color: var(--text-color);
      font-size: 1.2rem;
      background-color: var(--background-color);
      border-radius: var(--border-radius);
      box-shadow: var(--box-shadow);
      appearance: none;
      border: 0;
    }
    
    .button:hover {
      background-color: var(--background-color-hover);
    }
    
    @media only screen and (min-width: 40em) {
      .button {
        margin-bottom: 0;
      }
    }
  </style>
  <button class="button">
    Button
  </button>
</template>

<div class="faux-grid">
  <div class="stage">
    <some-elem></some-elem>
  </div>
  
  <div class="sidebar"></div>
</div>
              
            
!

CSS

              
                // Breakpoints Mixin
$breakpoints: (
  // small: var(--small)
  small: 0,
  medium: 40em,
  large: 64em
);

@mixin breakpoint($breakpoint) {
  @if map-has-key($breakpoints, $breakpoint) {
    @if $breakpoint == 'small' {
      @media only screen and (max-width: map-get($breakpoints, medium)) {
        @content;
      }
    }
    @else if $breakpoint == 'medium' {
      @media only screen and (min-width: map-get($breakpoints, medium)) {
        @content;
      }
    }
    @else if $breakpoint == 'large' {
      @media only screen and (min-width: map-get($breakpoints, large)) {
        @content;
      }
    }
  }
  
  @else {
    @warn 'Not a valid breakpoint: ' + $breakpoint;
  }
}

// Reset
* {
  box-sizing: border-box;
  *:before,
  *:after {
    box-sizing: inherit;
  }
}

body {
  margin: 1rem;
  text-align: center;
}

// Custom Element
some-elem {
  @include breakpoint(medium) {
    --display: inline-block;
    --width: auto;
    --background-color: green;
    --background-color-hover: darkgreen;
  }
    
  @include breakpoint(large) {
    --background-color: yellowgreen;
    --text-color: black;
  }
}

// For Demo Only
.faux-grid {
  display: flex;
  height: 100vh;
  border: 1px solid black;

  .stage {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 2;
  }
  
  .sidebar {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: space-between;
    flex: 1;
    height: 100%;
    border-left: 1px solid black;
  }
}
              
            
!

JS

              
                // Web Component Declaration
class SomeElem extends HTMLElement {
  constructor() {
    super()

    const root = this.attachShadow({mode: 'open'})
    const temp = document.importNode(template.content, true)

    root.appendChild(temp)
  }
}

customElements.define('some-elem', SomeElem)

const customElement = document.querySelector('some-elem');
const sidebar = document.querySelector('.faux-grid .sidebar');
const elems = window.getComputedStyle(customElement);

// BUG IN CHROME - DOES NOT DISPLAY CSS CUSTOM PROPERTY NAMES AND THEREFORE DOESN'T RENDER
for (prop in elems) {
  const container = document.createElement('div');
  const label = document.createElement('label');
  const input = document.createElement('input');
  
  container.className = 'container';
  
  if (elems.hasOwnProperty(prop) && elems[prop].includes('--')) {
    label.setAttribute('for', elems[prop].replace('--', ''));
    label.innerHTML = elems[prop];
    input.setAttribute('id', elems[prop].replace('--', ''))
    input.setAttribute('type', 'text');
    input.value = elems.getPropertyValue(elems[prop]);

    const test = elems[prop]
    input.addEventListener('input', () => updateCustomProp(test, input.value));

    container.appendChild(label);
    container.appendChild(input);
    sidebar.appendChild(container);
  }
}

updateCustomProp = (propertyName, value) => {
  document.querySelector('some-elem').style.setProperty(propertyName, value);
}
              
            
!
999px

Console