Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <body class="dark">
  <div class="notification close">
    ✔️ Copied
  </div>
  <div class="logo">
    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-palette" width="35" height="35" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
      <path stroke="none" d="M0 0h24v24H0z" />
      <path d="M12 21a9 9 0 1 1 0 -18a9 8 0 0 1 9 8a4.5 4 0 0 1 -4.5 4h-2.5a2 2 0 0 0 -1 3.75a1.3 1.3 0 0 1 -1 2.25" />
      <circle cx="7.5" cy="10.5" r=".5" fill="currentColor" />
      <circle cx="12" cy="7.5" r=".5" fill="currentColor" />
      <circle cx="16.5" cy="10.5" r=".5" fill="currentColor" />
    </svg>
  </div>
  <div class="theme-switch">
    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-sun theme-icon active" width="32" height="32" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
      <path stroke="none" d="M0 0h24v24H0z" />
      <circle cx="12" cy="12" r="4" />
      <path d="M3 12h1M12 3v1M20 12h1M12 20v1M5.6 5.6l.7 .7M18.4 5.6l-.7 .7M17.7 17.7l.7 .7M6.3 17.7l-.7 .7" />
    </svg>
    <svg xmlns="http://www.w3.org/2000/svg" class="icon theme-icon icon-moon" width="32" height="32" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
      <path stroke="none" d="M0 0h24v24H0z" />
      <path d="M16.2 4a9.03 9.03 0 1 0 3.9 12a6.5 6.5 0 1 1 -3.9 -12" />
    </svg>
  </div>
  <div class="wrapper">
    <main>
      <h1 class="head">PALETTE</h1>
      <div class="palette">
        <div class="color"></div>
        <div class="color"></div>
        <div class="color"></div>
        <div class="color"></div>
      </div>
      <button type="button" class="btn">GENERATE</button>
    </main>
  </div>
  <textarea name="copyArea" cols="30" rows="3" style="position: absolute; left: -9999px; top: 0;"></textarea>
</body>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  outline: 0;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

button {
  border: none;
  background-color: #eee;
  cursor: pointer;
}

.dark {
  --btn-clr: #42506b;
  --txt-clr: #fff;
  --background: #2a3950;
}

.light {
  --btn-clr: #3e619b;
  --txt-clr: #333;
  --background: #f5f5f5;
}

body {
  background-color: var(--background);
  color: var(--txt-clr);
}

.notification {
  position: absolute;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  left: 50%;
  top: 0;
  height: 3rem;
  width: 8rem;
  background-color: #90ee90;
  color: white;
  -webkit-transition: -webkit-transform 0.25s ease-in-out;
  transition: -webkit-transform 0.25s ease-in-out;
  transition: transform 0.25s ease-in-out;
  transition: transform 0.25s ease-in-out, -webkit-transform 0.25s ease-in-out;
  font-family: sans-serif;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

.notification.close {
  -webkit-transform: translate(-50%, -3rem);
  transform: translate(-50%, -3rem);
}

.logo {
  position: absolute;
  top: 3.5rem;
  left: 3.5rem;
}

.theme-switch {
  position: absolute;
  right: 6rem;
  top: 3.5rem;
  cursor: pointer;
}

.theme-switch svg {
  display: none;
  position: absolute;
}

.theme-switch svg.active {
  display: block;
}

.wrapper {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  min-height: 100vh;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

h1,
.head,
.btn {
  letter-spacing: 0.1875rem;
}

h1 {
  font-family: Montserrat, sans-serif;
  margin-bottom: 3rem;
  text-align: center;
}

.btn {
  font-family: Lato, sans-serif;
  padding: 1rem 2.5rem;
  border-radius: 3rem;
  background-color: var(--btn-clr);
  color: white;
  display: block;
  margin: 2.5rem auto 0 auto;
}

.btn:active {
  -webkit-transform: scale(0.96);
  transform: scale(0.96);
}

.palette {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.palette .color {
  height: 20rem;
  width: 6.25rem;
  background-color: #eee;
  -ms-flex-negative: 1;
  flex-shrink: 1;
  -webkit-box-flex: 0;
  -ms-flex-positive: 0;
  flex-grow: 0;
  border-radius: 3rem;
  cursor: pointer;
}

.palette .color:hover {
  -webkit-transform: scale(1.05);
  transform: scale(1.05);
}

.palette .color:active {
  -webkit-transform: scale(1);
  transform: scale(1);
}

.palette .color + .color {
  margin-left: 1rem;
}

              
            
!

JS

              
                // GLobal Variables

let themeSwitch = document.querySelector(".theme-switch");
let colors = document.querySelectorAll(".color");
let palette = document.querySelector(".palette");
let hex = "abcdef123456789";

//  Theme switcher function
themeSwitch.addEventListener("click", () => {
  document.querySelectorAll(".theme-icon").forEach((icon) => {
    if (icon.classList.contains("active")) {
      icon.classList.remove("active");
      document.body.classList.toggle("light");
    } else icon.classList.add("active");
  });
});

// Generate random hex

let randHex = () => {
  let hexString = "#";
  for (let i = 0; i < 6; i++) {
    hexString += hex[Math.round(Math.random() * 6)];
  }

  return hexString;
};

const copyToClipboard = (str) => {
  let el = document.querySelector("textarea");
  el.value = str;
  el.select();
  el.setSelectionRange(0, 99999);

  document.execCommand("copy");
};

// generate colors
let generate = () => {
  colors.forEach((color) => {
    color.style.backgroundColor = randHex();
  });
};
generate();

// Generate colors on click
document.querySelector(".btn").addEventListener("click", generate);

palette.addEventListener("click", (e) => {
  if (e.target.classList.contains("color")) {
    let color = e.target;
    copyToClipboard(window.getComputedStyle(color).backgroundColor);
    document.querySelector(".notification").classList.remove("close");
    setTimeout(() => {
      document.querySelector(".notification").classList.add("close");
    }, 1800);
  }
});

              
            
!
999px

Console