Color Picker using HTML & CSS3

In this example below you will see how to do a Color Picker using HTML & CSS3 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by rupok, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright rupok ©
  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Color Picker using HTML & CSS3</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="colorPicker">
  <input type="radio" name="color" value="color" checked="checked" id="1" />
  <label for="1"></label>
  <input type="radio" name="color" value="color" id="2" />
  <label for="2"></label>
  <input type="radio" name="color" value="color" id="3" />
  <label for="3"></label>
  <input type="radio" name="color" value="color" id="4" />
  <label for="4"></label>
  <input type="radio" name="color" value="color" id="5" />
  <label for="5"></label>
  <input type="radio" name="color" value="color" id="6" />
  <label for="6"></label>
  <input type="radio" name="color" value="color" id="7" />
  <label for="7"></label>
  <input type="radio" name="color" value="color" id="8" />
  <label for="8"></label>
  <input type="radio" name="color" value="color" id="9" />
  <label for="9"></label>
  <input type="radio" name="color" value="color" id="10" />
  <label for="10"></label>
  <input type="radio" name="color" value="color" id="11" />
  <label for="11"></label>
  <input type="radio" name="color" value="color" id="12" />
  <label for="12"></label>
  <input type="radio" name="color" value="color" id="13" />
  <label for="13"></label>
  <input type="radio" name="color" value="color" id="14" />
  <label for="14"></label>
  <input type="radio" name="color" value="color" id="15" />
  <label for="15"></label>
  <input type="radio" name="color" value="color" id="16" />
  <label for="16"></label>
  <input type="radio" name="color" value="color" id="17" />
  <label for="17"></label>
  <input type="radio" name="color" value="color" id="18" />
  <label for="18"></label>
  <input type="radio" name="color" value="color" id="19" />
  <label for="19"></label>
  <input type="radio" name="color" value="color" id="20" />
  <label for="20"></label>
  <input type="radio" name="color" value="color" id="21" />
  <label for="21"></label>
  <input type="radio" name="color" value="color" id="22" />
  <label for="22"></label>
  <input type="radio" name="color" value="color" id="23" />
  <label for="23"></label>
  <input type="radio" name="color" value="color" id="24" />
  <label for="24"></label>
  <input type="radio" name="color" value="color" id="25" />
  <label for="25"></label>
  <input type="radio" name="color" value="color" id="26" />
  <label for="26"></label>
  <input type="radio" name="color" value="color" id="27" />
  <label for="27"></label>
  <input type="radio" name="color" value="color" id="28" />
  <label for="28"></label>
  <input type="radio" name="color" value="color" id="29" />
  <label for="29"></label>
  <input type="radio" name="color" value="color" id="30" />
  <label for="30"></label>
  <input type="radio" name="color" value="color" id="31" />
  <label for="31"></label>
  <input type="radio" name="color" value="color" id="32" />
  <label for="32"></label>
  <input type="radio" name="color" value="color" id="33" />
  <label for="33"></label>
  <input type="radio" name="color" value="color" id="34" />
  <label for="34"></label>
  <input type="radio" name="color" value="color" id="35" />
  <label for="35"></label>
  <input type="radio" name="color" value="color" id="36" />
  <label for="36"></label>
  <div id="colorDisplay"></div> 
</div>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/rupok/color-picker-using-html-andamp-css3-Axhli */
body {
  background: black;
  text-align: center;
}

input { display: none; }

#colorDisplay{
  position: fixed;
  border: 1px solid white;
  top: 100px;
  left: 40%;
  width: 150px;
  height: 150px;
  display: inline-block;
}

#colorPicker {
  border-radius: 5px;
  padding: 0;
  height: 35px;
  width: 541px;
  position: auto;
  bottom: 0px;
  margin: 0 auto;  
  background: linear-gradient(to right, 
    hsla(0, 50%, 50%, 0.5),
hsla(10, 50%, 50%, 0.5),
hsla(20, 50%, 50%, 0.5),
hsla(30, 50%, 50%, 0.5),
hsla(40, 50%, 50%, 0.5),
hsla(50, 50%, 50%, 0.5),
hsla(60, 50%, 50%, 0.5),
hsla(70, 50%, 50%, 0.5),
hsla(80, 50%, 50%, 0.5),
hsla(90, 50%, 50%, 0.5),
hsla(100, 50%, 50%, 0.5),
hsla(110, 50%, 50%, 0.5),
hsla(120, 50%, 50%, 0.5),
hsla(130, 50%, 50%, 0.5),
hsla(140, 50%, 50%, 0.5),
hsla(150, 50%, 50%, 0.5),
hsla(160, 50%, 50%, 0.5),
hsla(170, 50%, 50%, 0.5),
hsla(180, 50%, 50%, 0.5),
hsla(190, 50%, 50%, 0.5),
hsla(200, 50%, 50%, 0.5),
hsla(210, 50%, 50%, 0.5),
hsla(220, 50%, 50%, 0.5),
hsla(230, 50%, 50%, 0.5),
hsla(240, 50%, 50%, 0.5),
hsla(250, 50%, 50%, 0.5),
hsla(260, 50%, 50%, 0.5),
hsla(270, 50%, 50%, 0.5),
hsla(280, 50%, 50%, 0.5),
hsla(290, 50%, 50%, 0.5),
hsla(300, 50%, 50%, 0.5),
hsla(310, 50%, 50%, 0.5),
hsla(320, 50%, 50%, 0.5),
hsla(330, 50%, 50%, 0.5),
hsla(340, 50%, 50%, 0.5),
hsla(350, 50%, 50%, 0.5)
);
}

label { 
  display: inline-block;
  height: 35px;
  width: 15px;
  float: left;
}

input:checked + label { border-left: 1px solid white; }

input:nth-child(1):checked ~ #colorDisplay { background: hsla(0, 50%, 50%, 0.5); }
input:nth-child(3):checked ~ #colorDisplay {   background: hsla(10, 50%, 50%, 0.5);}
input:nth-child(5):checked ~ #colorDisplay {  background: hsla(20, 50%, 50%, 0.5);}
input:nth-child(7):checked ~ #colorDisplay {  background: hsla(30, 50%, 50%, 0.5);}
input:nth-child(9):checked ~ #colorDisplay {  background: hsla(40, 50%, 50%, 0.5);}
input:nth-child(11):checked ~ #colorDisplay {  background: hsla(50, 50%, 50%, 0.5);}
input:nth-child(13):checked ~ #colorDisplay {  background: hsla(60, 50%, 50%, 0.5);}
input:nth-child(15):checked ~ #colorDisplay {  background: hsla(70, 50%, 50%, 0.5);}
input:nth-child(17):checked ~ #colorDisplay {  background: hsla(80, 50%, 50%, 0.5);}
input:nth-child(19):checked ~ #colorDisplay {  background: hsla(90, 50%, 50%, 0.5);}
input:nth-child(21):checked ~ #colorDisplay {  background: hsla(100, 50%, 50%, 0.5);}
input:nth-child(23):checked ~ #colorDisplay {  background: hsla(110, 50%, 50%, 0.5);}
input:nth-child(25):checked ~ #colorDisplay {  background: hsla(120, 50%, 50%, 0.5);}
input:nth-child(27):checked ~ #colorDisplay {  background: hsla(130, 50%, 50%, 0.5);}
input:nth-child(29):checked ~ #colorDisplay {  background: hsla(140, 50%, 50%, 0.5);}
input:nth-child(31):checked ~ #colorDisplay {  background: hsla(150, 50%, 50%, 0.5);}
input:nth-child(33):checked ~ #colorDisplay {  background: hsla(160, 50%, 50%, 0.5);}
input:nth-child(35):checked ~ #colorDisplay {  background: hsla(170, 50%, 50%, 0.5);}
input:nth-child(37):checked ~ #colorDisplay {  background: hsla(180, 50%, 50%, 0.5);}
input:nth-child(39):checked ~ #colorDisplay {  background: hsla(190, 50%, 50%, 0.5);}
input:nth-child(41):checked ~ #colorDisplay {  background: hsla(200, 50%, 50%, 0.5);}
input:nth-child(43):checked ~ #colorDisplay {  background: hsla(210, 50%, 50%, 0.5);}
input:nth-child(45):checked ~ #colorDisplay {  background: hsla(220, 50%, 50%, 0.5);}
input:nth-child(47):checked ~ #colorDisplay {  background: hsla(230, 50%, 50%, 0.5);}
input:nth-child(49):checked ~ #colorDisplay {  background: hsla(240, 50%, 50%, 0.5);}
input:nth-child(51):checked ~ #colorDisplay {  background: hsla(250, 50%, 50%, 0.5);}
input:nth-child(53):checked ~ #colorDisplay {  background: hsla(260, 50%, 50%, 0.5);}
input:nth-child(55):checked ~ #colorDisplay {  background: hsla(270, 50%, 50%, 0.5);}
input:nth-child(57):checked ~ #colorDisplay {  background: hsla(280, 50%, 50%, 0.5);}
input:nth-child(59):checked ~ #colorDisplay {  background: hsla(290, 50%, 50%, 0.5);}
input:nth-child(61):checked ~ #colorDisplay {  background: hsla(300, 50%, 50%, 0.5);}
input:nth-child(63):checked ~ #colorDisplay {  background: hsla(310, 50%, 50%, 0.5);}
input:nth-child(65):checked ~ #colorDisplay {  background: hsla(320, 50%, 50%, 0.5);}
input:nth-child(67):checked ~ #colorDisplay {  background: hsla(330, 50%, 50%, 0.5);}
input:nth-child(69):checked ~ #colorDisplay {  background: hsla(340, 50%, 50%, 0.5);}
input:nth-child(71):checked ~ #colorDisplay {  background: hsla(350, 50%, 50%, 0.5);}

label:nth-child(2):hover ~ #colorDisplay {  background: hsla(0, 50%, 50%, 0.5);}
label:nth-child(4):hover ~ #colorDisplay {  background: hsla(10, 50%, 50%, 0.5);}
label:nth-child(6):hover ~ #colorDisplay {  background: hsla(20, 50%, 50%, 0.5);}
label:nth-child(8):hover ~ #colorDisplay {  background: hsla(30, 50%, 50%, 0.5);}
label:nth-child(10):hover ~ #colorDisplay {  background: hsla(40, 50%, 50%, 0.5);}
label:nth-child(12):hover ~ #colorDisplay {  background: hsla(50, 50%, 50%, 0.5);}
label:nth-child(14):hover ~ #colorDisplay {  background: hsla(60, 50%, 50%, 0.5);}
label:nth-child(16):hover ~ #colorDisplay {  background: hsla(70, 50%, 50%, 0.5);}
label:nth-child(18):hover ~ #colorDisplay {  background: hsla(80, 50%, 50%, 0.5);}
label:nth-child(20):hover ~ #colorDisplay {  background: hsla(90, 50%, 50%, 0.5);}
label:nth-child(22):hover ~ #colorDisplay {  background: hsla(100, 50%, 50%, 0.5);}
label:nth-child(24):hover ~ #colorDisplay {  background: hsla(110, 50%, 50%, 0.5);}
label:nth-child(26):hover ~ #colorDisplay {  background: hsla(120, 50%, 50%, 0.5);}
label:nth-child(28):hover ~ #colorDisplay {  background: hsla(130, 50%, 50%, 0.5);}
label:nth-child(30):hover ~ #colorDisplay {  background: hsla(140, 50%, 50%, 0.5);}
label:nth-child(32):hover ~ #colorDisplay {  background: hsla(150, 50%, 50%, 0.5);}
label:nth-child(34):hover ~ #colorDisplay {  background: hsla(160, 50%, 50%, 0.5);}
label:nth-child(36):hover ~ #colorDisplay {  background: hsla(170, 50%, 50%, 0.5);}
label:nth-child(38):hover ~ #colorDisplay {  background: hsla(180, 50%, 50%, 0.5);}
label:nth-child(40):hover ~ #colorDisplay {  background: hsla(190, 50%, 50%, 0.5);}
label:nth-child(42):hover ~ #colorDisplay {  background: hsla(200, 50%, 50%, 0.5);}
label:nth-child(44):hover ~ #colorDisplay {  background: hsla(210, 50%, 50%, 0.5);
}label:nth-child(46):hover ~ #colorDisplay {  background: hsla(220, 50%, 50%, 0.5);}
label:nth-child(48):hover ~ #colorDisplay {  background: hsla(230, 50%, 50%, 0.5);}
label:nth-child(50):hover ~ #colorDisplay {  background: hsla(240, 50%, 50%, 0.5);}
label:nth-child(52):hover ~ #colorDisplay {  background: hsla(250, 50%, 50%, 0.5);}
label:nth-child(54):hover ~ #colorDisplay {  background: hsla(260, 50%, 50%, 0.5);}
label:nth-child(56):hover ~ #colorDisplay {  background: hsla(270, 50%, 50%, 0.5);}
label:nth-child(58):hover ~ #colorDisplay {  background: hsla(280, 50%, 50%, 0.5);}
label:nth-child(60):hover ~ #colorDisplay {  background: hsla(290, 50%, 50%, 0.5);}
label:nth-child(62):hover ~ #colorDisplay {  background: hsla(300, 50%, 50%, 0.5);}
label:nth-child(64):hover ~ #colorDisplay {  background: hsla(310, 50%, 50%, 0.5);}
label:nth-child(66):hover ~ #colorDisplay {  background: hsla(320, 50%, 50%, 0.5);}
label:nth-child(68):hover ~ #colorDisplay {  background: hsla(330, 50%, 50%, 0.5);}
label:nth-child(70):hover ~ #colorDisplay {  background: hsla(340, 50%, 50%, 0.5);}
label:nth-child(72):hover ~ #colorDisplay {  background: hsla(350, 50%, 50%, 0.5);}

Comments