Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


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


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.


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.


                <h1>CSS level 4 color contrast adjuster just with custom properties and calc()</h1>

  <label><strong>Background lightness</strong></label><input type="range" name="--bg-l" value="35"/><code></code>
  <label>Background hue</label><input type="range" name="--bg-h" value="180" min="0" max="360"/><code></code>
  <label>Background saturation</label><input type="range" name="--bg-s" value="100"/><code></code>
  <label><strong>Contrast ratio</strong></label><input type="range" name="--contrast-ratio" value="30"/><code></code>


  The CSS level 4 contrast adjuster mimicked with just custom properties and calc().
  While it's pretty straightforward to mimick the hue, saturation and
  lightness adjusters, color contrast requires some "serious" math.
  Results are not perfect, but very much usable IMHO.
  Syntax of course is even more bloated than for the simple adjusters mentioned above.
body {
  /* Actual values set from JS */
  --bg-h: 0; --bg-s: 0; --bg-l: 0; /* Background hue, saturation, lightness. */
  /* The ratio for the contrast() adjuster,
     see */
  --contrast-ratio: 0%;
h1 {
  /* If you see a red foreground,
     you might have a syntax error somwehere below this. */
  color: hsl(0, 100%, 50%);

  /* This is how colors need to be specified.
     Conversion of saturation and lightness to percentage done here
     to enable prior calculations. */
  background-color: hsl(
    calc(var(--bg-s) * 1%),
    calc(var(--bg-l) * 1%)

  /* The foreground color with contrast adjuster. */
  color: hsl(
    calc(var(--bg-s) * 1%),
    /* Calculate the lightness:
       1. Take the 1/x function
       2. Turn it upside down: -1/x
       2. Adjust it to the x and y axis, but avoid -Infinity being hit,
          since it tends to act funny when used in further calculations
          (make sure the input lightness value is rounded to at most 2 decimal points):
       3. Make it less curved, so the y-axis makes sense between 0 and 100:
       4. Adjust the curve with the contrast ratio,
          but make sure we're never multiplying by 0: (-2500*(c/100+1))/(x-49.999)+x
    calc((-2500 * (var(--contrast-ratio) * 1% / 100 + 1%)) / (var(--bg-l) - 49.999) + var(--bg-l) * 1%)

/* A few demo styles. */
body {
  font-family: system, -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
form {
  display: grid;
  grid-template-columns: minmax(min-content, max-content) max-content max-content;
  grid-gap: .5em;
  align-items: center;
code { text-align: right }
h1 {
  font-weight: bold;
  font-size: 26px;
  padding: 1em;


                const updateStyle = element =>, element.value) || (element.nextElementSibling.innerText = element.value)
Array.from(document.querySelectorAll('input')).forEach(input => updateStyle(input))
document.addEventListener('input', ({ target }) => requestAnimationFrame(() => updateStyle(target)))