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

              
                <html>

<!-- Default -->

<div class="wrapper">
  <h1>Default</h1>
  <div class="group-block has-default-bg">
    <p>Some normal text without a background color.</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-light">
    <p>Some normal text nested inside a light palette color background should match the default above since the brightness is relatively the same.</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-dark">
    <p>Some normal text nested inside a dark palette color background gets reversed to stay accessible.</p>
    <button>Button</button>
  </div>
</div>
  
<!-- Dark Mode Wrong -->

<div class="wrapper is-dark-theme-wrong">
  <h1>Dark Mode Bad? ☹️</h1>
  <p>When we keep the same palette colors for both normal and dark-mode we lose the contrast relationships needed to to distinguish foreground & background colors.</p> 
  <p><i>This is currently in Twenty Twenty One.</i></p>
  <div class="group-block has-default-bg">
    <p>Some normal text without a background color.βœ…</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-light">
    <p>Some normal text nested inside a light palette color background is illegible.🚫</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-dark">
    <p>Some normal text nested inside a dark palette color background is also illegible.🚫</p>
    <button>Button</button>
  </div>
</div>

<!-- Dark Mode Correct -->

<div class="wrapper is-dark-theme-correct-1">
  <h1>Dark Mode Good #1! πŸ˜€</h1>
  <p>When the pastel palette colors are darkened/lightened to properly express dark-mode, we can retain the correct contrast for text, buttons, etc. (ie: foreground) as they relate to the background palette color.</p>
  <div class="group-block has-default-bg">
    <p>Some normal text without a background color.βœ…</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-light">
    <p>Some normal text nested inside a light palette color background matches the dark-mode default since the brightness is relatively the sameβœ…</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-dark">
    <p>Some normal text nested inside a dark palette color background gets reversed to stay accessible in dark-mode.βœ…</p>
    <button>Button</button>
  </div>
</div>
  
<div class="wrapper is-dark-theme-correct-2">
  <h1>Dark Mode Good #2! πŸ˜€</h1>
  <p>When the pastel palette colors are darkened/lightened to properly express dark-mode, we can retain the correct contrast for text, buttons, etc. (ie: foreground) as they relate to the background palette color.</p>
  <div class="group-block has-default-bg">
    <p>Some normal text without a background color.βœ…</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-light">
    <p>Some normal text nested inside a light palette color background matches the dark-mode default since the brightness is relatively the sameβœ…</p>
    <button>Button</button>
  </div>

  <div class="group-block has-palette-bg-dark">
    <p>Some normal text nested inside a dark palette color background gets reversed to stay accessible in dark-mode.βœ…</p>
    <button>Button</button>
  </div>
</div>
</html>
              
            
!

CSS

              
                /* CSS Variables */
:root {
  --fore-color: #222222;
  --back-color: #DDDDDD;
  --palette-color-light: PaleGreen;   /* pastel light green */
  --palette-color-dark: MidnightBlue; /* pastel dark blue */
}

/* Utility Classes */
.has-palette-bg-light {
  color: var(--fore-color);
  background-color: var(--palette-color-light);
}

.has-palette-bg-dark {
  color: var(--back-color);
  background-color: var(--palette-color-dark);
}

/* Default wrappers */
.wrapper {
  color: var(--fore-color);
  background: var(--back-color);
}

/* Buttons */
button {
  background-color: var(--fore-color);
  border: solid 3px transparent;
  color: var(--back-color);
}

/* - Reversing button contrast */
.has-palette-bg-dark button {
  color: var(--fore-color);
  background-color: var(--back-color);
}

.has-palette-bg-light button{
  color: var(--back-color);
  background-color: var(--fore-color);
}

/* - Hover state is entirely relative */
button:hover {
  background-color: transparent;
  border-color: currentColor;
  color: inherit;
}

.is-dark-theme-wrong {
  --fore-color: #DDDDDD;
  --back-color: #222222;
}

/* SOLUTION #1
This works because it accounts for 
   ALL palette colors in darkmode */
.is-dark-theme-correct-1 {
  --fore-color: #DDDDDD;
  --back-color: #222222;
  --palette-color-light: SeaGreen; /* pastel dark green */
  --palette-color-dark: LightBlue; /* pastel light blue */
}

/* SOLUTION #2
   This works because it reverses 
   the text color for nested blocks
   in dark-mode */
.is-dark-theme-correct-2 {
  --fore-color: #DDDDDD;
  --back-color: #222222;
}

.is-dark-theme-correct-2 .has-palette-bg-light {
  color: var(--back-color);
}

.is-dark-theme-correct-2 .has-palette-bg-dark {
  color: var(--fore-color);
}

/* - Reversing button contrast */
.is-dark-theme-correct-2 .has-palette-bg-dark button {
  color: var(--back-color);
  background-color: var(--fore-color);
}

.is-dark-theme-correct-2 .has-palette-bg-light button {
  color: var(--fore-color);
  background-color: var(--back-color);
}

.is-dark-theme-correct-2 button:hover {
  color: inherit;
  background-color: transparent;
}













/* Other non-essential presentation styles (ignore) */

body {
  padding: 0;
  margin: 0;
}

.wrapper {
  margin: 0 auto 2em;
  padding: 2em;
  text-align: center;
}

.wrapper:last-of-type {
  margin-bottom: 0;
}

.group-block {
  padding: 2em;
}

button {
  cursor: pointer;
  display: block;
  font-weight: bolder;
  margin: 2em auto;
  padding: 1em 2em;
}

              
            
!

JS

              
                
              
            
!
999px

Console