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

              
                <section>
  <h1>CSS Color-Mix() - Base Color Percentage Demo</h1>

  <p>Using the CSS color-mix() function, we can experiment with the results of different base mix percentages. This feature is currently (15.4.2022) only available behind flags in Firefox and <a href="https://developer.apple.com/safari/technology-preview/">Safari Technology Preview</a>.</p>

  <section class="colors-container">
    <div></div>
    <div></div>
    <div id="result">50%</div>
  </section>

  <label>Adjust Base Mixture Percentage <input type="range" min="0" max="100" step="1" id="percent-slider" value="50" />

    <p>🚀 Bonus: We're using CSS color-contrast() to display the base percentage value.</p>
</section>

<div class="not-supported">The color-mix() feature is not supported in your browser.</div>
              
            
!

CSS

              
                body {
  --base-color: var(--color-secondary);
  --blend-color: var(--color-primary);
  --mix-percent: 50%;
}

.colors-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;

  div {
    block-size: 100px;
    inline-size: 100px;

    &:first-child {
      background: var(--base-color);
    }
    &:nth-child(2) {
      background: var(--blend-color);
    }
    &:last-child {
      --result-color: color-mix(
        in hsl,
        var(--base-color) var(--mix-percent),
        var(--blend-color)
      );
      background: var(--result-color);
      color: color-contrast(var(--result-color) vs black, white to AA);
      display: grid;
      place-items: center;
    }
  }
}

/* GLOBAL */
:root {
  --body-bg: #fff1e6;
  --color-text: #000;
  --color-link: #011627;

  --color-primary: #e71d36;
  --color-secondary: #2ec4b6;
  --color-accent: #ff9f1c;

  --scrollbar-bg: #222;
}

body::-webkit-scrollbar {
  width: 10px;
}
body {
  scrollbar-width: thin;
  scrollbar-color: var(--color-primary) var(--scrollbar-bg);
}
body::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}
body::-webkit-scrollbar-thumb {
  background-color: var(--color-primary);
  border-radius: 6px;
  border: 3px solid var(--scrollbar-bg);
}

html,
body {
  color: var(--color-text);
  font-family: "Barlow", sans-serif;
  font-size: 100%;
  letter-spacing: 0.25px;
  line-height: 1.75;
  margin: 0;
  padding: 0;
}

body {
  accent-color: var(--color-accent);
  background: var(--body-bg);
  background: linear-gradient(
    70deg,
    var(--body-bg) 0%,
    var(--body-bg) 86%,
    var(--color-accent) 86%,
    var(--color-accent) 87%,
    var(--body-bg) 87%,
    var(--body-bg) 91%,
    var(--color-secondary) 91%,
    var(--color-secondary) 95%,
    var(--color-primary) 95%,
    var(--color-primary) 100%
  );
  block-size: 100%;
  display: grid;
  min-block-size: 100vh;
  place-items: center;
}

a {
  color: var(--color-link);
  text-decoration: underline 1px dashed;
  text-underline-offset: min(5px, 1em);

  &:hover {
    color: color-mix(in srgb, var(--color-link) 90%, var(--color-secondary));
  }

  &:focus {
    outline: 1px solid currentColor;
    outline-offset: 3px;
  }
}

h1,
h2 {
  font-family: "Hubballi", cursive;
  line-height: 1.25;
}

section {
  inline-size: min(750px, 60vw);
}

.not-supported {
  background: #600;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  position: fixed;
  inset-block-end: 1rem;
  inset-inline-start: 1rem;

  @supports (background: color-mix(in srgb, #34c9eb 10%, white)) {
    display: none;
  }
}

label {
  display: grid;
  font-weight: 700;
  grid-gap: 0.5rem;
  place-items: center;
}

              
            
!

JS

              
                document.getElementById("percent-slider").addEventListener("input", (e) => {
  document.body.style.setProperty("--mix-percent", e.target.value + "%");
  document.querySelector("#result").innerHTML = e.target.value + "%";
});

              
            
!
999px

Console