css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <div class="container">
  <div  class="row top"><div class="col-md-12"><h1> Bulk Hex Color Converter</h1></div></div>
  <div class="row">
    <div class="col-md-6">
      <p>Paste 6 digit hex values separated by commas to convert.<br>You can include or exclude the #.<br>Saved values and tables are stored in localStorage for your next visit.</p>
      <input class="form-control" id="hexArr" value="#f44336,#E91E63,#9C27B0">
      <button class="btn btn-sm btn-success" id="button">Add to Current Table</button>
      <button class="btn btn-sm btn-danger" id="clear">Clear Current Table</button><br>
      <button class="btn btn-sm btn-success" id="save">Save Input Values</button>
      <button class="btn btn-sm btn-primary" id="retrieve">Retrieve Saved Input Values</button>
      <button class="btn btn-sm btn-danger" id="clearSave">Clear Input Memory</button><br>
      <button class="btn btn-sm btn-success" id="saveTable">Save Table</button>
      <button class="btn btn-sm btn-primary" id="retrieveTable">Retrieve Saved  Table</button>


      <button class="btn btn-sm btn-danger" id="clearSaveTable">Clear Table Memory</button>
    </div>
    <div class="col-md-6">
      <p class="alert"></p>
      <div class="table-responsive">
      <table class="table" id="father">
        <thead>
          <tr>
            <th>hex</th>
            <th>rgba</th>
            <th>hsl</th>
            <th>&nbsp;</th>
          </tr>
        </thead>
      </table>
      </div>
    </div>
    
  </div>
  <div class="row foot"><div class="col-md-4 col-md-offset-4 text-center"><p>Created by <a href="http://rmcd.io">Robert McDonald</a></p>
    </div></div>
</div>
            
          
!
            
              body{
  font-family:Sans-serif;
  background-color:#B0BEC5;
  margin-top:25vh;
}
@media screen and (max-width:992px){
  body{
    margin-top:5vh;
  }
}
.box{
  padding:10px;
  max-width:10px;

}
.btn {
  margin:5px 0;
}
thead{
  background-color:#455A64;
  color:#FAFAFA;
}
.alert{
  display:none;
}
.foot{
  margin-top: 5vh;
}
.foot a{
  color:#fff;
}
            
          
!
            
              /* global $ */
$(document).ready(function(){
var hexValues;
   //////////////////////////////////////////////////
  //Thank you to http://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/  for the detailed explanation of how to convert rgb to hsl, which I based this code off of.
 /////////////////////////////////////////////////////
 function HSL(a,b,c){
    a = a/255;
    b = b/255;
    c = c/255;
    var max = Math.max(a,b,c);
    var min = Math.min(a,b,c);
    var lum = (((max + min)/2)*100).toFixed(1);
    var hue,sat;
    if (min == max){
      hue=0;
      sat=0;
    }
    else if(lum<50){
      sat = (((max-min)/(max+min)*100)).toFixed(1);
    }
    else {
      sat = (((max-min)/(2-max-min)*100)).toFixed(1);
    }
    if (hue !== 0 && a == Math.max(a,b,c)){
      hue = Math.round((b-c)/(max-min)*60);
    }
    else if (hue !== 0 && b == Math.max(a,b,c)){
      hue = Math.round(2+((c-a)/(max-min))*60);
    }
    else if (hue !== 0){
      hue = Math.round((4 + ((a-b)/(max-min)))*60);    
             }
   if (hue<0){hue+=360;}
    return '<td>hsl('+hue+','+sat+'&#37,'+lum+'&#37;)</td>';
  }
  function convert(){
    hexValues = $('#hexArr').val();
    hexValues = hexValues.replace(/\#|\s+/g, '');
    var hexArr = hexValues.split(',');
    for (i=0;i<hexArr.length;i++){
      if(hexArr[i]===""){i++};
      var R = parseInt(hexArr[i].slice(0,2),16);
      var G = parseInt(hexArr[i].slice(2,4),16);
      var B = parseInt(hexArr[i].slice(4,6),16);
      $('#father').append($('<tr class="'+hexArr[i]+'"><td>#' + hexArr[i] + '</td><td> rgba('+R+','+G+','+B+',1)</td>'+ HSL(R,G,B)+'<td class="box" style="background-color:rgba(' + R+','+G+','+B+',1)">&nbsp</td>'+'</tr>').hide().fadeIn());    
    }}
 
  $('#button').click(function(){convert();}  
  );
 $('#clear').click(function(){
   $('#father tr').slice(1).fadeOut();
 });
 $('#save').click(function(){
   localStorage.userHex = $('#hexArr').val();
   alert('Values saved to localStorage.userHex .');
 });
 $('#saveTable').click(function(){
   localStorage.userTable = $('#father').html();
   alert('Table saved to localStorage.userTable .');
 });
  $('#clearSave').click(function(){
   localStorage.removeItem("userHex");
    alert('localStorage.userHex cleared.');
 });
 $('#retrieve').click(function(){
  if (localStorage.userHex) {
   $('#hexArr').val(localStorage.userHex); 
 }
   
 else {alert('No stored values found!')}})
 
 $('#retrieveTable').click(function(){
  if (localStorage.userTable) {
   $('#father').html($(localStorage.userTable).hide().fadeIn()); 
 }
   
 else {alert('No stored table found!')}})
 
 $('#clearSaveTable').click(function(){
   localStorage.removeItem("userTable");
    alert('localStorage.userTable cleared.');
 });
});

            
          
!
999px
🕑 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.
Loading ..................

Console