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

              
                <body class="theme__dark">
  <div class="container hide-container">
    <pre>
      <code class="css-res"></code>
    </pre>
  </div>

  <div class="btns">
    <div class="col-1">
      <button class="generate">Generate</button>
      <button class="show">Show CSS</button>
      <button class="copy">Copy CSS</button>
    </div>
    <div class="col-2">
      <label class="checkbox-container">
        <input type="checkbox" class="checkbox noir-btn">
        <span class="checkmark">
          <svg stroke="currentColor" fill="none" stroke-width=".5" viewBox="0 0 15 15" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z" fill="currentColor"></path></svg>
        </span>
        <span class="checkbox-title">
          Noir
        </span>
      </label>
      <select name="blend-mode" id="blendMode" class="blend-mode">
        <option value="blend-one" selected>Blend One</option>
        <option value="blend-two">Blend Two</option>
        <option value="no-blend">No Blend</option>
      </select>
    </div>
  </div>
</body>
              
            
!

CSS

              
                :root {
  --d1: 320.54deg;
  --d2: 58.72deg;
  --d3: 121.28deg;
  --d4: 180deg;
  --d5: 52.23deg;
  --d6: 121.28deg;
  --d7: 50% 72.12% at 50% 50%;
  --d8: 72.37%;
  --p1: 0%;
  --p2: 100%;
  --p3: .5%;
  --blend-one: screen, color-dodge, color-burn, screen, overlay, difference, color-dodge;
  --blend-two: screen, color-dodge, color-burn, screen, overlay, difference;
  --no-blend: inherit;
  --c1: #AF1015;
  --c2: #E03CDE;
  --c3: #8149D3;
  --c4: #2A257C;
  --c5: #E7F02D;
  --c6: #D65462;
  --c7: #2FF264;
  --c8: #4E6FB5;
  --c9: #B8771A;
  --c10: #F9DD63;
  --c11: #8294A6;
  --c12: #DB9175;
  --c13: #972465;
  --c14: #E8C7ED;
  --c15: #5E08A7;
  --c16: #F35EEE;
  --c17: #8CB64E;
  --c18: #2D7D19;
  --c19: #9BF7FF;
  --c20: #6637D4;
}

.theme__dark {
  --primaryFont: "Inter", sans-serif, -apple-system, ui-sans-serif, system-ui, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, monospace;
  --accent-1: #111;
  --accent-2: #222;
  --accent-3: #333;
  --accent-4: #444;
  --black0: #000;
  --black1: #0e0e0f;
  --white1: #fff;
  --white2: #cccbcb;
}

*,
*:before,
*:after {
  border: 0;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
}

html {
  line-height: 1.15;
  -moz-tab-size: 4;
  -o-tab-size: 4;
  tab-size: 4;
  font-size: 20px;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: var(--primaryFont);
  background:
  linear-gradient(var(--d1), var(--c1) var(--p1), var(--c11) var(--d8)),
    linear-gradient(var(--d2), var(--c2) var(--p1), var(--c12) var(--p2)),
    linear-gradient(var(--d3), var(--c3) var(--p1), var(--c13) var(--p2)),
    linear-gradient(var(--d3), var(--c4) var(--p1), var(--c14) var(--p2)),
    linear-gradient(var(--d4),var(--c5) var(--p1), var(--c15) var(--p3),var(--c17) var(--p2)),
    linear-gradient(var(--d5), var(--c6) var(--p1), var(--c16) var(--p2)),
    linear-gradient(var(--d6), var(--c7) var(--p1), var(--c10) var(--p2)),
    radial-gradient(var(--d7), var(--c8) var(--p1), var(--c9) var(--p2));
  height: 100vh;
  width: 100%;
  color: var(--white1);
  text-rendering: optimizeSpeed;
  font-size: 1rem;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: inherit;
  position: relative;
  overflow: hidden;
  background-blend-mode: var(--blend-one);
  backdrop-filter: none;
}

.hide-container {
  display: none;
}

.container {
  position: absolute;
  top: 0;
  left: 0;
  padding: 6rem .5rem 0 .5rem;
  background: rgba(23, 23, 23, 0.8);
  width: 100%;
  height: 100vh;
  word-wrap: break-word;
  overflow: hidden;
  z-index: 100;
}

pre {
  height: 100%;
  overflow-y: scroll;
  width: 100%;
  font-size: .875rem;
}

.btns {
  position: absolute;
  display: grid;
  grid-template-columns: 1fr 140px;
  top: 0;
  left: 0;
  z-index: 200;
  margin: auto;
  width: 100%;
  height: 4rem;
  padding: .5rem;
}

.col-1,
.col-2 {
  display: flex;
  width: 100%;
}

.col-1 {
  justify-content: flex-start;
}

.col-2 {
  justify-content: flex-end;
  flex-direction: column;
}

.btns button {
  align-items: center;
  border-radius: 5px;
  display: flex;
  filter: brightness(.9) contrast(1.2);
  background: linear-gradient(to right bottom, var(--accent-3), var(--accent-1));
  color: var(--white1);
  border: 1px solid var(--accent-4);
  font-size: .875rem;
  height: 2.25rem;
  padding: 0 0.875rem;
  text-align: center;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
  white-space: nowrap;
  cursor: pointer;
  margin-right: .5rem;
}

.btns .generate {
  background: var(--c3);
}

.btns button:not(.generate):hover {
  background: linear-gradient(to right bottom, rgba(50, 145, 255, .25), var(--accent-1));
}

.btns button:not(.generate):active {
  background: #222;
}

.btns .generate:hover {
  filter: brightness(1.2) contrast(1.2);
}

.btns .generate:active {
  filter: brightness(1.3) contrast(1.3);
}

.checkbox-container,
.blend-mode {
  filter: brightness(.9) contrast(1.2);
  color: var(--white1);
  font-size: .875rem;
  display: flex;
  background: var(--black0);
  border: 1px solid var(--accent-4);
  align-items: center;
  padding: 0 0.875rem 0 .5rem;
  justify-content: space-between;
  height: 2.25rem;
  border-radius: 5px;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.blend-mode {
  margin-top: .5rem;
}

.checkbox-container:hover {
  background: linear-gradient(to right bottom, var(--accent-3), var(--accent-1));
}

.checkbox {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  visibility: hidden;
  cursor: pointer;
  z-index: -1;
}

.checkmark {
  border: 1px solid var(--white2);
  background: black;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 2px;
  width: 1.25rem;
  height: 1.25rem;
  margin-right: .75rem;
}

.checkmark svg {
  display: none;
  height: 100%;
  width: 100%;
}

.checkbox:checked ~ .checkmark svg {
  display: block;
  color: var(--black0);
}

.checkbox:checked ~ .checkmark {
  background: var(--white2);
}

@media screen and (max-width: 1080px) {
  html {
    font-size: 16px;
  }
}

@media screen and (max-width: 768px) {
  html {
    font-size: 14px;
  }
}

@media screen and (max-width: 480px) {
  html {
    font-size: 13px;
  }
}

@media screen and (max-width: 360px) {
  html {
    font-size: 12px;
  }
}
              
            
!

JS

              
                const rs = document.querySelector(":root");
const body = document.querySelector("body");
const container = document.querySelector(".container");
const btnsContainer = document.querySelector(".btns");
const cssres = document.querySelector('.css-res');
const generateBtn = document.querySelector('.generate');
const blendMode = document.querySelector('.blend-mode');
const noirBtn = document.querySelector('.noir-btn');

const baseCSS = `
:root {\n  --d1: 320.54deg;\n  --d2: 58.72deg;\n  --d3: 121.28deg;\n  --d4: 180deg;\n  --d5: 52.23deg;\n  --d6: 121.28deg;\n  --d7: 50% 72.12% at 50% 50%;\n  --d8: 72.37%;\n  --p1: 0%;\n  --p2: 100%;\n  --p3: .5%;\n  --blend-one: screen, color-dodge, color-burn, screen, overlay, difference, color-dodge;\n  --blend-two: screen, color-dodge, color-burn, screen, overlay, difference;\n  --no-blend: inherit;\n
`;
const gradientStr = `linear-gradient(var(--d1), var(--c1) var(--p1), var(--c11) var(--d8)),\n    linear-gradient(var(--d2), var(--c2) var(--p1), var(--c12) var(--p2)),\n    linear-gradient(var(--d3), var(--c3) var(--p1), var(--c13) var(--p2)),\n    linear-gradient(var(--d3), var(--c4) var(--p1), var(--c14) var(--p2)),\n    linear-gradient(var(--d4),var(--c5) var(--p1), var(--c15) var(--p3),var(--c17) var(--p2)),\n    linear-gradient(var(--d5), var(--c6) var(--p1), var(--c16) var(--p2)),\n    linear-gradient(var(--d6), var(--c7) var(--p1), var(--c10) var(--p2)),\n    radial-gradient(var(--d7), var(--c8) var(--p1), var(--c9) var(--p2));`;
const [heightStr, widthStr] = ['height:100vh;\n', 'width:100%;\n'];
const getBackdropFilterStr = () => `backdrop-filter: ${noirBtn.checked ? 'grayscale(100%) contrast(1.3)' : 'none'};\n`;
const getBackgroundBlendModeStr = () => `background-blend-mode: var(--${blendMode.value});\n`;

const generateRandomColor = (i) => {
  const color = '#' + Array.from({ length: 6 }).map(() => '0123456789ABCDEF'[Math.floor(Math.random() * 16)]).join('');
  rs.style.setProperty(`--c${i}`, color);
  return color;
};

const generateCSS = () => {
  let css = baseCSS, resBG = '';
  for (let i = 1; i <= 20; i++) {
    css += `  --c${i}: ${generateRandomColor(i)};\n`;
    resBG += `var(--c${i}) var(--p1), `;
  }
  body.style.background = gradientStr;
  body.style.backgroundBlendMode = `var(--${blendMode.value})`;
  body.style.backdropFilter = noirBtn.checked ? 'grayscale(100%) contrast(1.3)' : 'none';
  cssres.innerText = css + '}' + '\n\n' + `body {\n  background:\n  ${gradientStr}\n  ${getBackgroundBlendModeStr()}  ${heightStr}  ${widthStr}  ${getBackdropFilterStr()}}`;
  css = '';
};

const handleCopy = (e) => {
  if (e.target.innerText === "Copied!") return;
  const text = cssres.innerText;
  if (text) {
    navigator.clipboard.writeText(text);
    e.target.innerText = "Copied!";
    setTimeout(() => e.target.innerText = "Copy CSS", 1000);
  }
};

const getTextColor = (colorString) => {
  const convertHexToRGB = hex => {
    const hexValue = hex.replace('#', '');
    const r = parseInt(hexValue.substring(0, 2), 16);
    const g = parseInt(hexValue.substring(2, 4), 16);
    const b = parseInt(hexValue.substring(4, 6), 16);
    return `rgb(${r}, ${g}, ${b})`;
  };
  colorString = convertHexToRGB(colorString);

  let match = colorString.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);
  if (!match) { return 'white'; }
  const [nr, ng, nb] = [match[1], match[2], match[3]].map(n => parseInt(n, 10));
  return (nr * 299 + ng * 587 + nb * 114) / 1000 > 128 ? 'black' : 'white';
};

const handleNoir = () => {
  const bfRes = noirBtn.checked ? 'grayscale(100%) contrast(1.3)' : 'none';
  body.style.backdropFilter = bfRes;
  const regex = /backdrop-filter: (.*?);/g;
  cssres.innerHTML = cssres.innerHTML.replace(regex, `backdrop-filter: ${bfRes};`);
};

const handleBlendMode = (e) => {
  const newBlendMode = `var(--${e.target.value})`;
  body.style.backgroundBlendMode = newBlendMode;
  const regex = /background-blend-mode: (.*?);/g;
  cssres.innerHTML = cssres.innerHTML.replace(regex, `background-blend-mode: ${newBlendMode};`);
};

const handleBtns = (e) => {
  const generate = e.target.closest('.generate');
  const show = e.target.closest('.show');
  const copy = e.target.closest('.copy');
  const noir = e.target.closest('.noir-btn');
  if (generate) {
    generateCSS();
    const c3 = window.getComputedStyle(rs).getPropertyValue('--c3');
    generateBtn.style.color = getTextColor(c3);
  }
  if (show) {
    container.classList.toggle('hide-container');
    show.innerText = show.innerText === 'Show CSS' ? 'Hide CSS' : 'Show CSS';
  }
  if (copy) { handleCopy(e); }
  if (noir) { handleNoir(); }
};

document.querySelector('.noir-btn').checked = false;
btnsContainer.addEventListener('click', handleBtns);
blendMode.addEventListener('change', handleBlendMode);
const setExampleOutput = () => {
  let exampleCSS = baseCSS;
  exampleCSS += `\n  --c1: #AF1015;\n  --c2: #E03CDE;\n  --c3: #8149D3;\n  --c4: #2A257C;\n  --c5: #E7F02D;\n  --c6: #D65462;\n  --c7: #2FF264;\n  --c8: #4E6FB5;\n  --c9: #B8771A;\n  --c10: #F9DD63;\n  --c11: #8294A6;\n  --c12: #DB9175;\n  --c13: #972465;\n  --c14: #E8C7ED;\n  --c15: #5E08A7;\n  --c16: #F35EEE;\n  --c17: #8CB64E;\n  --c18: #2D7D19;\n  --c19: #9BF7FF;\n  --c20: #6637D4;\n}`;
  exampleCSS += `\nbody{\n  background:\n  ${gradientStr}\n  ${getBackgroundBlendModeStr()}  ${heightStr}  ${widthStr}  ${getBackdropFilterStr()}}`;
  cssres.innerText = exampleCSS;
};
setExampleOutput();
              
            
!
999px

Console