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

              
                <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>
              
            
!

CSS

              
                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;
}
              
            
!

JS

              
                /* 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

Console