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>Attempt at mixins, an example for the <a href="https://kizu.dev/layered-toggles/" target="_blank">layered toggles</a> article</h1>

<p>This example uses flex and grid layouts adapted from the <a href="https://smolcss.dev/" target="_blank">SmolCSS</a> project by <a href="https://thinkdobecreate.com/" target="_blank">Stephanie Eckles</a>.</p>

<p>Grid one works everywhere, where @layer is supported.</p>
<p>Flex one fully works only with style queries, as it requires styling the direct child (so only Chrome and Safari TP).</p>

<ol role="list">
  <li role="listitem">Item</li>
  <li role="listitem">Item</li>
  <li role="listitem">Item</li>
  <li role="listitem">Item</li>
</ol>

<ul role="list">
  <li role="listitem">Item</li>
  <li role="listitem">Item</li>
  <li role="listitem">Item</li>
  <li role="listitem">Item</li>
</ul>

<p>You can see how we can have <em>an element</em> with non-default display, and it not being affected by the mixins, even though they're defined with the universal selector, and involve adjusting the display property!</p>
              
            
!

CSS

              
                
:where(em) {
  display: inline-block;
  background: pink;
  padding: 0.25em;
  border-radius: 9em;
}

li {
  padding: 1em;
  box-sizing: border-box;
  background: var(--item-bg);
  border-radius: 1em;
  list-style-type: none;
}

ol,
ul {
  padding: 0;
  --min: 30ch;
}

ol {
  --layout: var(--smol-grid);
  --item-bg: lightgreen;
}

ul {
  --layout: var(--smol-flex);
  --item-bg: pink;
}

/* Due to layers, the display is not overridden even when having zero specificity. */

/* The mixins! */
* {
  /* Common variables. Ideally, we'd want to use `revert-layer` for them as well, but there is currently a number of issues with this: https://github.com/w3c/csswg-drafts/issues/9131 */
  @layer defaults {
    --min: 15ch;
    --gap: 1rem;
  }

  /* Layout mixins */
  /* Code adapted from https://smolcss.dev/ by Stephanie Eckles. */
  @layer {
    --layout: var(--no-layout);
    --no-layout: var(--layout,);
    --smol-grid: var(--layout,);
    --smol-flex: var(--layout,);

    display:
      var(--no-layout, revert-layer)
      var(--smol-grid, grid)
      var(--smol-flex, flex);
    gap:
      var(--no-layout, revert-layer)
      var(--smol-grid, var(--gap))
      var(--smol-flex, var(--gap));
    grid-template-columns:
      var(--no-layout, revert-layer)
      var(--smol-grid,
       repeat(
         auto-fit,
         minmax(
           min(100%, var(--min)),
           1fr
         )
       )
      )
      var(--smol-flex, revert-layer)
      ;
    flex-wrap: 
      var(--no-layout, revert-layer)
      var(--smol-grid, revert-layer)
      var(--smol-flex, wrap)
      ;
    @container not style(--smol-flex: ) {
      /* Otherwise, it will be reset on `*` */
      --min: inherit;
      flex: 1 1 var(--min);
    }
    
  }
  
}

              
            
!

JS

              
                
              
            
!
999px

Console