Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="styles.css">
    <title>Color picker</title>
        <div class="colorWrapper">
    <h1>Pick a color:</h1>
    <input type="color" value="#e48100">
    <div class="colorInfo">
        <div class="hexInfo">
            <p><strong>HEX:</strong> <span class="hexValue"></span></p>
        <div class="rgbInfo">
            <p><strong>RGB: </strong><span class="redValue"></span> <span class="blueValue"></span> <span class="greenValue"></span></p>
        <div class="hslInfo">
            <p><strong>HSL: </strong><span class="hueValue"></span> <span class="saturationValue"></span> <span class="lightnessValue"></span></p>
    <script src="scripts.js"></script>
              @import url('https://fonts.googleapis.com/css?family=Raleway:400,700&display=swap');

h1 {
    font-family: "Raleway", sans-serif;
    font-weight: 700;
body {
    text-align: center;
    font-family: "Raleway", sans-serif;

/* --- COLOR --- */

.colorInfo {
    display: flex;
    justify-content: center;

.hexInfo, .rgbInfo, .hslInfo {
    min-width: 200px;
    margin: 0 20px;
              "use strict";

const colorPicker = document.querySelector("input");

colorPicker.addEventListener("input", updateFirst);
colorPicker.addEventListener("change", showColorSample);

//updates the color sample as the user is browsing colors in the color picker
function updateFirst(event) {
  document.querySelector("body").style.background = event.target.value;

//updates the color picker and the color sample until new input
function showColorSample(event) {
  document.querySelector("body").style.background = event.target.value;
  document.querySelector(".hexValue").textContent = event.target.value;

function convertHEXtoRGB() {
  //split the HEX code into substrings
  let hex12 = event.target.value.substring(1, 3);
  let hex34 = event.target.value.substring(3, 5);
  let hex56 = event.target.value.substring(5, 7);

  function displayRGB() {
    //using parseInt on substring parts to get RGB values
    document.querySelector(".redValue").textContent = parseInt(hex12, 16);
    document.querySelector(".blueValue").textContent = parseInt(hex34, 16);
    document.querySelector(".greenValue").textContent = parseInt(hex56, 16);

function convertRGBtoHSL() {
  //converting RGB to HSL sponsored by Peter
  let r = 255;
  let g = 255;
  let b = 255;

  let h, s, l;

  const min = Math.min(r, g, b);
  const max = Math.max(r, g, b);

  if (max === min) {
    h = 0;
  } else if (max === r) {
    h = 60 * (0 + (g - b) / (max - min));
  } else if (max === g) {
    h = 60 * (2 + (b - r) / (max - min));
  } else if (max === b) {
    h = 60 * (4 + (r - g) / (max - min));

  if (h < 0) {
    h = h + 360;

  l = (min + max) / 2;

  if (max === 0 || min === 1) {
    s = 0;
  } else {
    s = (max - l) / Math.min(l, 1 - l);
  // multiply s and l by 100 to get the value in percent, rather than [0,1]
  s *= 100;
  l *= 100;

  console.log("hsl(%f,%f%,%f%)", h, s, l); // just for testing

  function displayHSL() {
    //putting HSL values into <p>
    document.querySelector(".hueValue").textContent = h;
    document.querySelector(".saturationValue").textContent = s;
    document.querySelector(".lightnessValue").textContent = l;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.