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

              
                <h1>Style Queries Demo</h1>
<p>
  This demo is based on
  an article at
  <a href="https://lea.verou.me/2020/10/the-var-space-hack-to-toggle-multiple-values-with-one-custom-property/">lea.verou.me</a> -
  and demonstrates different approaches
  for replacing the 'variable space hack'
  with container style queries.
  The main limitation here
  is that it's not possible for an element
  to query itself,
  so some form of nesting is required.
</p>

<section>
  <h2>Default</h2>
  <button>Flat</button>
</section>

<section class="context">
  <h2>Contextual variable setting</h2>
  <p>
    The <code>--button: raised;</code> value
    is set on the wrapping section,
    allowing the <code>button</code>
    to query the value.
  </p>
  <button>Raised</button>
</section>

<section class="internal">
  <h2>Internal variable setting</h2>
  <p>
    The <code>--button: raised;</code> value
    is set on the <code>button</code> itself,
    and the styles are applied
    to a nested <code>span</code>.
  </p>
  <button class="wrap"><span>Raised</span></button>
</section>
              
            
!

CSS

              
                button:not(.wrap),
button.wrap > span {
  padding: 0.6em 1em;
  border: 1px solid;
  border-radius: 0.2em;
  background: hsl(200 100% 50%);
  color: white;
  font: 600 100%/1 sans-serif;
  cursor: pointer;
}

button:hover {
  background-color: hsl(200 100% 40%);
}

.context,
.internal button {
  --button: raised;
}

@container style(--button: raised) {
  button:not(.wrap),
  button.wrap > span {
    border: 1px solid rgb(0 0 0 / 0.1);
    background: linear-gradient(hsl(0 0% 100% / 0.3), transparent)
      hsl(200, 100%, 50%);
    box-shadow: 0 1px hsl(0 0% 100% / 0.8) inset,
      0 0.1em 0.1em -0.1em rgb(0 0 0 / 0.2);
    text-shadow: 0 -1px 1px rgb(0 0 0 / 0.3);
  }

  button:active,
  .wrap > span:active {
    box-shadow: 0 1px 0.2em black inset;
  }
}

@layer init {
  html {
    height: 100%;
    display: grid;
  }
  body {
    padding: 1em;
  }
  button {
    padding: 0;
    margin: 0;
    border: 0;
    font: inherit;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console