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

              
                <link rel="stylesheet" href="https://unpkg.com/mvp.css" type="text/css">

<main>
  <p>Some colors need to be tweaked  in order to get nice visual results. Average chrome is around 0.2 and hue is incremented by values between 25 and 50.</p>
  <table class="color-table">
    <thead>
      <tr>
        <th></th>
        <th>50</th>
        <th>100</th>
        <th>200</th>
        <th>300</th>
        <th>400</th>
        <th>500</th>
        <th>600</th>
        <th>700</th>
        <th>800</th>
        <th>900</th>
      </tr>
    </thead>
    <tbody>
      <tr class="neutral">
        <th>neutral</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="gray">
        <th>gray</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="blue">
        <th>blue</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="indigo">
        <th>indigo</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="purple">
        <th>purple</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="pink">
        <th>pink</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="red">
        <th>red</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="orange">
        <th>orange</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="yellow">
        <th>yellow</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="green">
        <th>green</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="teal">
        <th>teal</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
      <tr class="cyan">
        <th>cyan</td>
        <td><button style="--l:95%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:90%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:80%;--color-btn:var(--color-text);"></button></td>
        <td><button style="--l:70%"></button></td>
        <td><button style="--l:60%"></button></td>
        <td><button style="--l:50%"></button></td>
        <td><button style="--l:40%"></button></td>
        <td><button style="--l:30%"></button></td>
        <td><button style="--l:20%"></button></td>
        <td><button style="--l:10%"></button></td>
      </tr>
    </tbody>
  </table>

  <hr>

  The APCA scoring system scores accessibility in levels out of 106 & -108. The higher the number, the higher the contrast. 15 is the minimum for non-text elements, while 75 is the preferred level for body text. Negative values means light text on dark background.
  <hr>
  <a href="https://caniuse.com/?search=oklch" target="blank">Browser support for OKLCH</a><br>
  <a href="https://caniuse.com/css-relative-colors" target="blank">Browser support for relative colors</a>
</main>
              
            
!

CSS

              
                /* Syntax is oklch(L C H / a) */
:root {
  --color-text: #212529;
  --color-btn: #fff;
  --gray-c: 0.015;
  --gray-h: 248;
  --blue-c: 0.225;
  --blue-h: 250;
  --indigo-c: 0.3;
  --indigo-h: 275;
  --purple-c: 0.2;
  --purple-h: 320;
  --pink-c: 0.25;
  --pink-h: 0;
  --red-c: 0.25;
  --red-h: 25;
  --orange-c: 0.25;
  --orange-h: 50;
  --yellow-c: 0.18;
  --yellow-h: 85;
  --green-c: 0.2;
  --green-h: 140;
  --teal-c: 0.2;
  --teal-h: 160;
  --cyan-c: 0.2;
  --cyan-h: 210;
}

/*This works with relative colors
  /*--color:rgb(from var(--blue) h s l);*/

.color-table button {
  --lv: var(--l);
  --l: 50%;
  --c: 0;
  --h: 0;
  --a: 100%;
  --color: oklch(var(--lv) var(--c) var(--h) / var(--a));
  width: 50px;
  padding: 0.5em;
  background-color: var(--color);
  border-color: var(--color);
  color: var(--color-btn);
}

.color-table button:hover {
  filter: none;
  --a: 75%;
}

.neutral button {
  --c: 0;
}

.gray button {
  --c: var(--gray-c);
  --h: var(--gray-h);
}

.blue button {
  --c: var(--blue-c);
  --h: var(--blue-h);
}
.indigo button {
  --c: var(--indigo-c);
  --h: var(--indigo-h);
}
.purple button {
  --c: var(--purple-c);
  --h: var(--purple-h);
}
.pink button {
  --c: var(--pink-c);
  --h: var(--pink-h);
}
.red button {
  --c: var(--red-c);
  --h: var(--red-h);
}
.orange button {
  --c: var(--orange-c);
  --h: var(--orange-h);
}
.yellow button {
  --c: var(--yellow-c);
  --h: var(--yellow-h);
}
.green button {
  --c: var(--green-c);
  --h: var(--green-h);
}
.teal button {
  --c: var(--teal-c);
  --h: var(--teal-h);
}
.cyan button {
  --c: var(--cyan-c);
  --h: var(--cyan-h);
}

              
            
!

JS

              
                import Color from "https://colorjs.io/dist/color.js";

document.querySelectorAll(".color-table button").forEach((btn) => {
  const styles = window.getComputedStyle(btn);
  const bg = styles.getPropertyValue("background-color");
  const color = styles.getPropertyValue("color");

  let text = new Color(color);
  let background = new Color(bg);
  let contrast = background.contrast(text, "APCA");

  if (contrast) {
    btn.innerHTML = contrast.toString().split(".")[0];
  }
});

              
            
!
999px

Console