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

              
                <p>Just setting the <code>--splash-bg</code> on <em>any</em> HTML element gives that element a background color, and a contrasting text color :)</p>
<span class="test" style="--splash-bg: 900"></span>
<span class="test" style="--splash-bg: 000"></span>
<span class="test" style="--splash-bg: 999"></span>
<span class="test" style="--splash-bg: 079"></span>

<h2>Resources:</h2>
<ul>
  <li><a href="https://www.todepond.com/lab/splash/" target="_blank">“Splash colour format”</a> by <a href="https://www.todepond.com/" target="_blank">Lu Wilson</a></li>
  <li><a href="https://lea.verou.me/blog/2024/contrast-color/" target="_blank">“On compliance vs readability: Generating text colors with CSS”</a> by <a href="https://lea.verou.me/" target="_blank">Lea Verou</a></li>
  <li><a href="https://kizu.dev/indirect-cyclic-conditions/" target="_blank">“Indirect Cyclic Conditions: Prototyping Parametrized CSS Mixins”</a> by <a href="https://kizu.dev/" target="_blank">Roma Komarov</a></li>
</ul>
              
            
!

CSS

              
                /* CSS Implementation of https://www.todepond.com/lab/splash/ */
/* A mixin prototype, see https://kizu.dev/indirect-cyclic-conditions/ for how this works */
@layer splash {
  * {
    /* Our input, with a list of “dependencies” */
    --splash-bg: var(--_splash-bg-value) var(--_splash-shadow) var(--_splash-color);

    /* Extracting the color components from the input */
    --_splash_r: round(down, var(--splash-bg) / 100, 1);
    --_splash_g: round(down, (var(--splash-bg) - var(--_splash_r) * 100) / 10, 1);
    --_splash_b: calc(var(--splash-bg) - var(--_splash_r) * 100 - var(--_splash_g) * 10);

    /* Normalizing the values to regular rgb: any changes and adjustements can go here */
    --_rgb_r: calc(var(--_splash_r) * 255/9);
    --_rgb_g: calc(var(--_splash_g) * 255/9);
    --_rgb_b: calc(var(--_splash_b) * 255/9);
    
    /* Assigning the actual value for the background color. */
    --_splash-bg-value: rgb(var(--_rgb_r), var(--_rgb_g), var(--_rgb_b));
    background: var(--_splash-bg-value, revert-layer);

    /* By default, adding a text-shadow (might be overridden later) */
    --_splash-shadow:
      Canvas 1px 1px 0px, Canvas -1px -1px 0px, Canvas 1px -1px 0px, Canvas -1px 1px 0px
      var(--WHEN, var(--_splash-bg-value));
    text-shadow: var(--_splash-shadow, revert-layer);

    /* If the browser supports relative colors, use them to assign a color instead of a shadow */
    /* See https://lea.verou.me/blog/2024/contrast-color/ for more details */
	  @supports (color: oklch(from red l c h)) {
		  --l: clamp(0, (l / var(--l-threshold, 0.71) - 1) * -infinity, 1);
      --_splash-color: oklch(from var(--_splash-bg-value) var(--l) 0 h) var(--WHEN, var(--splash-bg));
      color: var(--_splash-color, revert-layer);
      text-shadow: revert-layer;
    }
  }
}

:root {
  /* Required for indirect cyclic conditions */
  --WHEN: ;

  color-scheme: light dark;
}

.test {
  padding: 0.2em 0.4em;
  font: bold 1.3em/1.8 Helvetica, sans-serif;

  &::after {
    content: attr(style);
  }  
}

code {
  --splash-bg: 909;
}

em {
  --splash-bg: 099;
}
              
            
!

JS

              
                
              
            
!
999px

Console