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-Contrast() - Text and ::selection Demo</h1>

  <article>
    <h2>The Shining</h2>
    <p>A family heads to an isolated hotel for the winter where a sinister presence influences the father into violence, while his psychic son sees horrific forebodings from both past and future.</p>
  </article>

  <article>
    <h2>Incident in a Ghostland</h2>
    <p>A mother of two who inherits a house is confronted with murderous intruders on the first night in their new home and fights for her daughters' lives. Sixteen years later when the daughters reunite at the house, things get really strange.</p>
  </article>

  <p>🚀 Bonus: Highlight the text on the page to see the ::selection background use color-contrast().</p>
</section>

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

CSS

              
                article {
  --article-bg: #e9d8a6;
  --article-color: color-contrast(var(--article-bg) vs #fff, #000);

  background: var(--article-bg);
  color: var(--article-color);
  padding: 0.5rem 1rem;

  &:last-of-type {
    --article-bg: #001219;
  }

  ::selection {
    // The @supports function can let us use color-contrast() progressively
    @supports (background: color-contrast(#000 vs #fff, #eee)) {
      background: color-contrast(var(--article-color) vs #94d2bd, #005f73);

      /*
        Feel free to chain color-contrast() calls like this:
        background: color-contrast( color-contrast(var(--article-bg) vs #fff, #000) vs #94d2bd, #005f73);
      */
    }
  }
}

/* GLOBAL */
:root {
  --body-base: #fbf8cc;
  --color-primary: #94d2bd;
  --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: #000;
  font-family: "Barlow", sans-serif;
  font-size: 100%;
  letter-spacing: 0.25px;
  line-height: 1.75;
  margin: 0;
  padding: 0;
}

body {
  background-image: radial-gradient(
    circle farthest-corner at 108.9% 51.2%,
    var(--color-primary) 0%,
    var(--color-primary) 15.9%,
    #005f73 15.9%,
    #005f73 24.4%,
    var(--body-base) 24.5%,
    var(--body-base) 66%
  );
  block-size: 100%;
  display: grid;
  min-block-size: 100vh;
  place-items: center;
}

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

  &:hover {
    color: #131313;
  }

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

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

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

.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-contrast(#000 vs #fff, #eee)) {
    display: none;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console