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

              
                <main>
  <h1>Style queries with variable values</h1>
  <p>
    We can reference
    custom properties using <code>var()</code>
    inside
    <a href="https://drafts.csswg.org/css-contain-3/#style-container">style queries</a>.
    That means, for example,
    we can query if the <code>background-color</code>
    on the container
    is currently <code>var(--bg-light)</code> or
    <code>var(--bg-dark)</code>.
    Open up DevTools and toggle the light/dark mode
    paintbrush to see it work.
  </p>
  <p>
    Currently this demo requires
    Chrome/Edge 107+ with
    experimental-web-platform-features enabled
    in <code>about://flags</code>,
    as well as
    an extra <code>--background-color</code>
    variable to query, since the Chrome prototype
    does not support querying normal properties.
  </p>
  <pre><code>
@container theme style(--background-color: var(--bg-dark)) {
  /* styles for our dark theme */
}

@container theme style(--background-color: var(--bg-light)) {
  /* styles for our light theme */
}
</code></pre>
</main>
<footer>
  <p>
    This footer section uses a style query
    to apply the opposite of the root theme.
    You can tell it's a footer,
    because it includes my name with a link:
    <a href="https://miriamsuzanne.com">Miriam Suzanne</a>
  </p>
</footer>
              
            
!

CSS

              
                /* 
Currently the Chrome prototype
only allows us to query custom props,
so we use an extra `--background-color` variable.
For the ideal but unsupported solution see:
https://codepen.io/miriamsuzanne/pen/ExRvRrr
*/

html {
  --bg-dark: mediumvioletred;
  --bg-light: snow;
  --background-color: var(--bg-light);
  color: black;
}

html,
footer {
  background-color: var(--background-color);
  container-name: theme;
}

/* the root element responds to user preference */
@media (prefers-color-scheme: dark) {
  html {
    --background-color: var(--bg-dark);
    color: white;
  }
}

/* in a theme container with a light background… */
@container theme style(--background-color: var(--bg-light)) {
  /* the footer switches to dark mode */
  footer {
    --background-color: var(--bg-dark);
    color: white;
  }

  /* links have a dark color */
  a:any-link {
    color: mediumvioletred;
  }
}

/* in a theme container with a dark background… */
@container theme style(--background-color: var(--bg-dark)) {
  /* the footer switches to light mode */
  footer {
    --background-color: var(--bg-light);
    color: black;
  }

  /* links have a light color */
  a:any-link {
    color: snow;
  }
}

@layer init {
  * {
    box-sizing: border-box;
  }
  html {
    height: 100%;
  }
  body {
    min-height: 100%;
    display: grid;
    grid-template-columns: minmax(min-content, min(100%, 65ch));
    place-content: center;
    padding: 1em;
  }

  footer {
    padding: 1em;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console