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

              
                # Custom Cascades

by defining a cascade of custom properties,
you can determine which *intent* should take priority --
without worrying about the specificity
of how that value is defined.
in this case, my cascade includes:

- `--btn-bg--state`
- `--btn-bg`
- `--btn-bg--type`
- `--btn-bg--default`

Our default button is falling all the way back 
to the `--btn-bg--default` defined on `html`.

<button type="button">default</button>

Adding the `disabled` attribute
always overrides any other button colors --
no matter where they are defined.

<button type="button" disabled>disabled</button>

We can create button types using `--btn-bg--type`,
and it will override the defaults,
but not the state:

<button type="button" class="warn">warn</button>
<button type="button" class="go">go</button>
<button type="button" class="warn" disabled>warn disabled</button>
<button type="button" class="go" disabled>go disabled</button>

## Context & Specificity

We can also set these values contextually,
rather than directly styling the button.
Values can come from anywhere,
and true specificity only resolves conflicts
between the same custom property.

<form>
  
  In this case I set all form-buttons to use
  `deeppink` as the default, rather than `blue`.
  we can make contextual changes at a higher level
  of the cascade, if we want --
  like "disabling" the entire form.
  
  <button type="button">default</button>
    
  If we need to change a button based on user-input,
  or otherwise set it via html,
  we can do that too.
  I'm doing that with `--btn-bg`
  which comes second in the cascade.
  
  <button type="button" style="--btn-bg: rebeccapurple;">override</button>
  
  and we avoid the usual danger from inline styles high specificity.
  Because `state` is first in the cascade,
  it will always override the higher-specificity inline style:
  
  <button type="button" style="--btn-bg: rebeccapurple;" disabled>override disabled</button>
</form>
              
            
!

CSS

              
                /* defaults & overrides */
html {
  --btn-bg--default: blue;
}

button {
  background: var(--btn-bg--state, 
    var(--btn-bg, 
      var(--btn-bg--type, 
        var(--btn-bg--default)
      )
    )
  );
}

[disabled] {
  --btn-bg--state: gray;
}

.warn {
  --btn-bg--type: maroon;
}

.go {
  --btn-bg--type: darkgreen;
}

form {
  --btn-bg--default: deeppink;
}

body {
  padding: 1em;
  max-width: 45em;
  margin: 0 auto;
}

button {
  color: white;
  border: thin solid black;
  font: inherit;
  margin: 0.5em;
  padding: 0.5em 2em;
}
              
            
!

JS

              
                
              
            
!
999px

Console