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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="https://fonts.googleapis.com/css?family=Play&display=swap" rel="stylesheet">
</head>

<body>
  <div id="controls">
    <div id="marquee">
      <h1>Palette Panda</h1>
      <img id="panda" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1197275/pandaSmall.png" />
    </div>
    <label for="color">Pick a color:</label><input type="color" id="color" />
    <label for="hex" title="Represents the red, green, and blue values as a hexadecimal number">Hex:</label><input size=10 type="text" id="hex" />

    <label for="hexLabels">Show Hex:</label>
    <input checked type="checkbox" id="hexLabels">
    <label for="rgbLabels">Show RGB:</label>
    <input type="checkbox" id="rgbLabels">
    <label for="hslLabels">Show HSL:</label>
    <input type="checkbox" id="hslLabels">

    <div id="container">
      <label for="rbg" title="Red, Green, and Blue values">RGB:</label>
      <input id="red" class="rgb" type="number" min=0 max=255 />
      <input id="green" class="rgb" type="number" min=0 max=255 />
      <input id="blue" class="rgb" type="number" min=0 max=255 />
    </div>
    <div>
      <label for="hsl" title="Hue, Saturation, and Luminance values">HSL:</label>
      <input id="hue" class="hsl" type="number" min=0 max=240 />
      <input id="saturation" class="hsl" type="number" min=0 max=240 />
      <input id="luminance" class="hsl" type="number" min=0 max=240 />
    </div>
  </div>
  <div id="container">
    <table id="colors">
      <tr>
        <td></td>
        <td></td>
        <td>
          <div class="rowLabel" title="A palette of three like colors and two complements (180° hue distance)">Complement</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td>
          <div class="rowLabel" title="Includes the two 'triad' hues to the seed color (120° in either direction)">Triads</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td>
          <div class="rowLabel" title="Includes the two hues adjacent to the pure complement (150° in either direction)">Split Complements</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td>
          <div class="rowLabel" title="Includes hues 15 and 30° in either direction of the seed color">Analogs</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td>
          <div class="rowLabel" title="Varies saturation and luminance, but not hue">Monochrome</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td>
          <div class="rowLabel" title="Desaturated seed plus analog (30° hue distance), tetrad (90°) and triad (120°)">Desaturated</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>
        </td>
        <td></td>
        <td>
          <div class="rowLabel" title="Saturated seed plus analog (30° hue distance), tetrad (90°) and triad (120°)">Saturated</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>
        </td>
        <td></td>
        <td>
          <div class="rowLabel" title="Evenly spaced (in terms of hue distance) colors">Spectrum</div>
        </td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>
        </td>
        <td></td>
        <td>
          <div class="rowLabel" title="Hue and saturation are constant, with varying luminance">Shades</div>
        </td>
        <td></td>
        <td></td>
      </tr>
    </table>
  </div>

</body>
              
            
!

CSS

              
                html,
body,
th,
h1 {
  margin: 0px;
  padding: 0px;
}

body {
  height: 100vh;
  width: 100vw;
  background-color: aliceblue;
  font-family: "Play", sans-serif;
  text-align: center;
  display:flex;
  flex-direction:column;
}
#container {
  flex:1 1 auto;
}

table#colors {
   width:100%;
   height:100%;
}

#colors td {
  width: 20%;
  text-align: center;
  padding: 3px;
}

#controls {
  color: black;
  padding: 5px;
}

#controls div {
  padding: 3px;
}

div.rowLabel {
  padding: 5px;
}

h1 {
  display: inline;
  padding: 5px;
}
#marquee {
  display: flex;
  justify-content: center;
  align-items: center;
}
#panda {
  height: 50px;
}

              
            
!

JS

              
                    /*INIT*/
    var $color = $("#color")
    var $hex = $("#hex")
    var $r = $("#red")
    var $g = $("#green")
    var $b = $("#blue")
    var $h = $("#hue")
    var $s = $("#saturation")
    var $l = $("#luminance")

    /*main function*/
    $color.change(function (ev) {
        let tiny = tinycolor(ev.target.value)
        let hex = ev.target.value
        let text = readableComplement(hex)
        $('body').css("color", text)

        $hex.val(hex)
        let tinyHsl = tiny.toHsl()
        $r.val(tiny._r)
        $b.val(tiny._b)
        $g.val(tiny._g)
        let pickerHue = Math.round((tinyHsl.h / 360) * 240)
        $h.val(pickerHue)
        $s.val(Math.round(tinyHsl.s * 240))
        $l.val(Math.round(tinyHsl.l * 240))

        let comps = complements(hex)
        setColors($('tr:eq(0)'), comps)
        let tryads = triads(hex)
        setColors($('tr:eq(1)'), tryads)
        let splits = splitComplements(hex)
        setColors($('tr:eq(2)'), splits)
        let logs = analogs(hex)
        setColors($('tr:eq(3)'), logs)
        let mono = monochrome(hex)
        setColors($('tr:eq(4)'), mono)
        let wash = desaturated(hex)
        setColors($('tr:eq(5)'), wash)
        let brights = saturated(hex)
        setColors($('tr:eq(6)'), brights)
        let spec = spectrum(hex)
        setColors($('tr:eq(7)'), spec)
        let shade = shades(hex)
        setColors($('tr:eq(8)'), shade)

    })
    /*change functions*/
    $(".hsl").change(function (ev) {
        let fullHue = ($h.val() / 240) * 360
        let hsl = (h, s, l) => {
            return `hsl ${h} ${s} ${l}`
        }
        let hslStr = hsl(fullHue, ($s.val() / 240), ($l.val() / 240))
        let hexStr = tinycolor(hslStr).toHexString()
        $color.val(hexStr).trigger("change")
    })
    $(".rgb").change(function (ev) {
        let rgbStr = `rgb ${$r.val()} ${$g.val()} ${$b.val()}`
        let tiny = tinycolor(rgbStr)
        $color.val(tiny.toHexString()).trigger("change")
    })
    $hex.change(function (ev) {
        $color.val(ev.target.value).trigger("change")
    })
    $('[type="checkbox"]').change(function (e) {
        $color.trigger("change")
    })

    /*front page action, show the palette of a random color*/
    var rando = tinycolor.random().toHexString()
    $color.val(rando).trigger("change")

    /*palette functions*/
    function spectrum(hex) {
        let c1 = tinycolor(hex).spin(-144).toHexString()
        let c2 = tinycolor(hex).spin(-72).toHexString()
        let c3 = hex
        let c4 = tinycolor(hex).spin(72).toHexString()
        let c5 = tinycolor(hex).spin(144).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    function desaturated(hex) {
        const desatFactor = (tinycolor(hex).toHsl().s / 2) * 100
        let isDark = tinycolor(hex).isDark()
        let c1 = isDark ? tinycolor(hex).desaturate(desatFactor).brighten(20).toHexString() : tinycolor(hex).desaturate(desatFactor).darken(20).toHexString()
        let c2 = tinycolor(hex).desaturate(desatFactor).spin(120).toHexString()
        let c3 = tinycolor(hex).desaturate(desatFactor).toHexString()
        let c4 = tinycolor(hex).desaturate(desatFactor).spin(30).lighten(5).toHexString()
        let c5 = tinycolor(hex).desaturate(desatFactor).spin(90).toHexString()   
        return new Palette(c1, c2, c3, c4, c5)
    }

    function saturated(hex) {
        const satFactor = (tinycolor(hex).toHsl().s / 2) * 100
        let c1 = tinycolor(hex).spin(30).saturate(satFactor).lighten(10).toHexString()
        let c2 = tinycolor(hex).spin(15).saturate(satFactor).darken(10).toHexString()
        let c3 = tinycolor(hex).saturate(satFactor).toHexString()
        let c4 = tinycolor(hex).saturate(satFactor).spin(90).toHexString()
        let c5 = tinycolor(hex).saturate(satFactor).spin(120).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    function triads(hex) {
        
        let c1 = tinycolor(hex).desaturate(10).lighten(15).toHexString()
        let c2 = tinycolor(hex).spin(-120).toHexString()
        let c3 = hex
        let c4 = tinycolor(hex).spin(120).toHexString()
        let c5 = tinycolor(hex).spin(120).saturate(10).darken(15).toHexString() 
        return new Palette(c1, c2, c3, c4, c5)
    }

    function analogs(hex) {
      
        let c1 = tinycolor(hex).spin(-30).toHexString()        
        let c2 = tinycolor(hex).spin(-15).saturate(10).darken(10).toHexString()        
        let c3 = hex
        let c4 = tinycolor(hex).spin(15).desaturate(10).lighten(10).toHexString()
        let c5 = tinycolor(hex).spin(30).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    function splitComplements(hex) {
        
        let c1 = tinycolor(hex).spin(-150).saturate(10).darken(10).toHexString()
        let c2 = tinycolor(hex).spin(-150).toHexString()
        let c3 = hex
        let c4 = tinycolor(hex).spin(150).toHexString()
        let c5 = tinycolor(hex).spin(150).desaturate(10).lighten(10).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    function monochrome(hex) {

        let isDark = tinycolor(hex).isDark()
        let c1 = isDark ? tinycolor(hex).lighten(25).toHexString() : tinycolor(hex).darken(25).toHexString()
        let c2 = isDark ? tinycolor(hex).desaturate(25).lighten(5).toHexString() : tinycolor(hex).desaturate(25).darken(5).toHexString()
        let c3 = hex
        let c4 = isDark ? tinycolor(hex).saturate(25).lighten(5).toHexString() : tinycolor(hex).saturate(25).darken(5).toHexString()
        let c5 = isDark ? tinycolor(hex).lighten(35).toHexString() : tinycolor(hex).darken(35).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    function shades(hex) {

        let c1 = tinycolor(hex).lighten(30).toHexString()
        let c2 = tinycolor(hex).lighten(15).toHexString()
        let c3 = hex
        let c4 = tinycolor(hex).darken(15).toHexString()
        let c5 = tinycolor(hex).darken(30).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    function complements(hex) {
        
        let isDark = tinycolor(hex).isDark()
        let c1 = tinycolor(hex).saturate(10).darken(15).toHexString()
        let c2 = tinycolor(hex).desaturate(10).lighten(15).toHexString()
        let c3 = hex
        let c4 = tinycolor(hex).spin(180).toHexString()
        let c5 = isDark ? tinycolor(hex).spin(180).desaturate(10).lighten(15).toHexString() : tinycolor(hex).spin(180).saturate(10).darken(15).toHexString()
        return new Palette(c1, c2, c3, c4, c5)
    }

    /*HELPERS*/
    function Palette(c1, c2, c3, c4, c5) {
        this.c1 = c1
        this.c2 = c2
        this.c3 = c3
        this.c4 = c4
        this.c5 = c5
    }

    function readableComplement(hexColor) {

        let tiny = tinycolor(hexColor)
        let complement = tiny.complement()
        if (tiny.isDark()) {
            complement = complement.brighten(85)
        } else if (tiny.isLight()) {
            complement = complement.darken(70)
        }
        return complement.toHexString()
    }

    function setColors(row, palette) {

        let toRGB = (hex) => {
            let rgb = tinycolor(hex).toRgb()
            return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`
        }
        let toHSL = (hex) => {
            let tiny = tinycolor(hex).toHsl()
            return `hsl(${Math.round(tiny.h)}, ${Math.round(tiny.s*100)}%, ${Math.round(tiny.l*100)}%)`
        }

        function generateLabels(hex) {
            let htm = $('<div class="labels"></div>')
            if ($('#hexLabels')[0].checked) {
                htm.append(`<div>${hex}</div>`)
            }
            if ($('#rgbLabels')[0].checked) {
                htm.append(`<div>${toRGB(hex)}</div>`)
            }
            if ($('#hslLabels')[0].checked) {
                htm.append(`<div>${toHSL(hex)}</div>`)
            }
            return htm
        }

        $(row).find(".labels").remove()
        $(row).find('td:nth-child(1)').append(generateLabels(palette.c1)).css("background-color", palette.c1).css("color", readableComplement(palette.c1))
        $(row).find('td:nth-child(2)').append(generateLabels(palette.c2)).css("background-color", palette.c2).css("color", readableComplement(palette.c2))
        $(row).find('td:nth-child(3)').append(generateLabels(palette.c3)).css("background-color", palette.c3).css("color", readableComplement(palette.c3))
        $(row).find('td:nth-child(4)').append(generateLabels(palette.c4)).css("background-color", palette.c4).css("color", readableComplement(palette.c4))
        $(row).find('td:nth-child(5)').append(generateLabels(palette.c5)).css("background-color", palette.c5).css("color", readableComplement(palette.c5))
    }

              
            
!
999px

Console