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

Save Automatically?

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>I can <code>:has()</code> color scheme switcher</h1>
<p>The <code>:has()</code> selector can propagate DOM state anywhere else in the tree. Zero JS required.</p>
<form>
  <label>
    <input name="color-scheme" value="dark" type="radio" />
    Dark
  </label>
  <label>
    <input name="color-scheme" value="light" type="radio" />
    Light
  </label>
  <label>
    <input name="color-scheme" value="system" type="radio" checked />
    System
  </label>
</form>
<p>Read more on <a href="https://blog.jim-nielsen.com/2022/unlocked-possibilities-of-has-selector/">blog.jim-nielsen.com</a>.</p>
              
            
!

CSS

              
                /* By default, the system’s value is resepcted. This can be overriden with the user’s preference as expressed via the <form>. */

/* Setup default variables */
:root {
  --bg: #fff;
  --text: #222;
  --accent: #f44250;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #222;
    --text: #fff;
  }
}

/* Apply the defaults using variables */
:root {
  color-scheme: light dark;
  background-color: var(--bg);
  color: var(--text);
}

/* Setup overrides with pure CSS */
:root:has([name="color-scheme"][value="dark"]:checked) {
  --bg: #222;
  --text: #fff;
}
:root:has([name="color-scheme"][value="light"]:checked) {
  --bg: #fff;
  --text: #222;
}


/* Extra sparkles */
body {
  font-family: ui-sans-serif, sans-serif;
  max-width: 320px;
  margin: 0 auto;
  line-height: 1.3;
}
input {
  display: none;
}
form {
  display: flex;
  border: 1px solid;
  color: var(--accent);
  border-radius: 8px;
  overflow: hidden;
}
form label {
  width: 33.333%;
  text-align: center;
  padding: 8px 0;
}
form label:has(input:checked) {
  background-color: var(--accent);
  color: var(--bg);
}
form label:nth-child(2) {
  border-left: 0;
  border-right: 0;
}
a {
  color: inherit;
}
              
            
!

JS

              
                
              
            
!
999px

Console