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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                
<section class='panel channel-range channel-range--original'>
  
  <p class='panel__title'>Original range:</p>
  
  <div class='channel-range__gradient'>
    <span class='channel-range__limit channel-range__limit--lower' data-val='0'></span>
    <span class='channel-range__limit channel-range__limit--middle'></span>
    <span class='channel-range__limit channel-range__limit--upper' data-val='255'></span>

    <span class='channel-range__value' data-val='165'data-type='o'></span>
  </div>
  
</section>

<section class='panel channel-range channel-range--squished'>
  
  <p class='panel__title'>Squished range:</p>
  
  <div class='channel-range__gradient'>
    <span class='channel-range__limit channel-range__limit--lower' data-val='0'></span>
    <span class='channel-range__limit channel-range__limit--middle'></span>
    <span class='channel-range__limit channel-range__limit--upper' data-val='255'></span>

    <span class='channel-range__value channel-range__value--squished' data-val='165' data-type='s'></span>
    <span class='channel-range__value channel-range__value--inverted' data-val='90' data-type='i'></span>
  </div>
  
</section>

<section class='panel code--css' >
  
  <code>
    
    <span class='token token--property'>filter</span><!--
    --><span class='token token--punctuation'>:</span>
    <span class='token token--value'>
      <span class='token token--function-name'>invert</span><!--
      --><span class='token token--punctuation'>(</span><!--
      --><span class='token token--function-arg' contenteditable>65%</span><!--
      --><div class='controls'>
      <button class='arg-incr'>&#x25B2;</button>
      <button class='arg-decr'>&#x25BC;</button>
      <div class='slider'>
        <input type='range' value='1' min='0' max='1' step='.05' class='arg-modify'>
      </div>
      </div><!--
      --><span class='token token--punctuation'>)</span>
    </span>
  </code>
    
</section>

<section class='boxes'>
  <section class='box box--original' data-type='original' data-bg='rgb(255, 165, 0)'></section>
  <section class='box box--filtered' data-type='inverted' data-bg=''></section>
</section>
              
            
!

CSS

              
                @import "compass/css3";

* { box-sizing: inherit; }

html {
  box-sizing: border-box;
  min-width: 240px;
  background: gainsboro;
  font: 100%/2 verdana, sans-serif;
}

body { margin-top: -1em; }

button {
  cursor: pointer;
}

::-webkit-slider-track, ::-webkit-slider-runnable-track, ::-webkit-slider-thumb {
  cursor: pointer;
}

::-moz-range-track, ::-moz-range-thumb {
  cursor: pointer;
}

.channel-range {
  
  &__gradient {
    position: relative;
    margin: 2em auto;
    width: 80%; height: 1em;
    background: linear-gradient(to right, rgb(0, 0, 0), rgb(0, 255, 0));
    
    &:before {
      position: absolute;
      top: calc(50% - 1px);
      width: 100%; height: 2px;
      background: white;
      content: '';
    }
  }
  
  &__limit, &__value {
    position: absolute;
    top: 50%;
    cursor: pointer;
    
    &[data-val]:after {
      position: absolute;
      top: 50%; left: 50%;
      padding: 0 .5em;
      border-radius: .25em;
      transform: translate(-50%);
      box-shadow: inset 0 0 .25em grey;
      background: whitesmoke;
      content: attr(data-val);
    }
    
    &:hover { z-index: 2; }
  }
  
  &__limit {
    margin: -.5em -.125em;
    width: .25em; height: 1em;
    background: white;
    
    &--lower {
      left: 0;
    }
    &--middle {
      left: 50%;
      margin-left: -.125em;
    }
    &--upper {
      left: 100%;
    }
    
    &:after {
      margin-top: -2.75em;
    }
  }
  
  &__value {
    left: 165/255*100%;
    margin: -.25em;
    width: .5em; height: .5em;
    border-radius: 50%;
    background: white;
    
    &[data-val]:after {
      margin-top: .75em;
      content: attr(data-type) ':' attr(data-val);
    }
    
    &:hover {
      z-index: 2;
    }
  }
  
}

.code--css {
  margin: 2.25em .5em 0;
  padding: .25em 1em;
  border-radius: .25em;
  background: #191919;
  color: whitesmoke;
  font: 1.5em monospace;
}

.token {
  &--property { color: deeppink; }
  &--value { position: relative; }
  &--function-name { color: yellow; }
  &--function-arg { min-width: 2em; color: orange; }
  &--punctuation { color: whitesmoke; }
}

.controls {
  display: inline-block;
  margin-left: .25em;
  width: 1.5em;
  vertical-align: middle;
  
  button {
    float: left;
    width: 100%;
    line-height: 1;
    text-align: center;
  }
}

.slider {
  position: absolute;
  top: 150%; left: 0;
  padding: .5em .5em .25em;
  border-radius: 0 0 .25em .25em;
  background: #191919;
}

.boxes {
  margin: 4em 0 0;
}

.box {
  display: inline-block;
  position: relative;
  width: 10em; height: 5em;
  background: orange;
  
  &:before {
    position: absolute;
    bottom: 100%;
    content: attr(data-type);
  }
  &:after {
    position: absolute;
    top: 100%;
    content: attr(data-bg);
  }
}
              
            
!

JS

              
                var limit_upper = 255, 
    el_limit_upper = document.querySelector('.channel-range--squished .channel-range__limit--upper'), 
    limit_lower = 0, 
    el_limit_lower = document.querySelector('.channel-range--squished .channel-range__limit--lower'), 
    o_channel_val = document.querySelector('.channel-range--original .channel-range__value').dataset.val, 
    channel_val = o_channel_val, 
    el_channel_val = document.querySelector('.channel-range__value--squished'), 
    inv_channel_val = 255 - o_channel_val, 
    el_inv_channel_val = document.querySelector('.channel-range__value--inverted'), 
    el_arg_val = document.querySelector('.token--function-arg'), 
    arg_val = el_arg_val.textContent, 
    arg_type = 'percent', 
    el_arg_incr = document.querySelector('.arg-incr'), 
    el_arg_decr = document.querySelector('.arg-decr'), 
    el_arg_modif = document.querySelector('.arg-modify'), 
    el_original = document.querySelector('.box--original'), 
    original = getComputedStyle(el_original).backgroundColor, 
    el_filtered = document.querySelector('.box--filtered'), 
    filtered = 'rgb(89, 117, 166)';

var test_input = function(_arg) {
    
  if(_arg > 1) { _arg = 1; }
  if(_arg < 0) { _arg = 0; }
  
  if(_arg*1 != _arg) { _arg = 1; }
  
  return _arg*1;
};

var update_upper = function(_arg) {
  limit_upper = arg_val*255;
  el_limit_upper.dataset.val = Math.round(limit_upper);
  el_limit_upper.style.left = arg_val*100 + '%';
};

var update_lower = function(_arg) {
  limit_lower = (1 - arg_val)*255;
  el_limit_lower.dataset.val = Math.round(limit_lower);
  el_limit_lower.style.left = (1 - arg_val)*100 + '%';
};

var update_channel_val = function(_arg) {
  channel_val = limit_lower + o_channel_val*(limit_upper - limit_lower)/255;
  el_channel_val.dataset.val = Math.round(channel_val);
  el_channel_val.style.left = (channel_val/255)*100 + '%';
};

var update_inv_channel_val = function(_arg) {
  inv_channel_val = 255 - channel_val;
  el_inv_channel_val.dataset.val = Math.round(inv_channel_val);
  el_inv_channel_val.style.left = (inv_channel_val/255)*100 + '%';
};

var update_arg_val = function(_arg) {
  el_arg_val.textContent = (arg_type === 'percent')?(Math.round(arg_val*100) + '%'):arg_val.toFixed(2);
};

var update_slider = function(_arg) {
  el_arg_modif.value = test_input(_arg);
};

var update_filtered = function(_arg) {
  var channels = original.match(/\d+/g), 
      filtered_channels = channels.map(function(c){
        return Math.round(255 - (limit_lower + c*(limit_upper - limit_lower)/255));
      });
  filtered = 'rgb(' + filtered_channels.join(', ') +  ')';
  el_filtered.style.background = filtered;
  el_filtered.dataset.bg = filtered;
};

var update_all = function(_arg, o) {
  var o = o || 0;
  
  update_upper(_arg);
  update_lower(_arg);
  update_channel_val(_arg);
  update_inv_channel_val(_arg);
  update_filtered(_arg);
  
  if(o) { update_arg_val(_arg); }
  else { update_slider(_arg); }
};

/* init */
if(arg_val[arg_val.length - 1] === '%') {
  arg_type = 'percent';
  arg_val = arg_val.split('%')[0]/100;
}
arg_val = test_input(arg_val);
update_all(arg_val);


/* listeners */
el_arg_val.addEventListener('blur', function() {
  
  arg_val = this.textContent;
  
  if(arg_val[arg_val.length - 1] === '%') {
    arg_type = 'percent';
    arg_val = arg_val.split('%')[0]/100;
  }
  else { arg_type = 'decimal'; }
  
  arg_val = test_input(arg_val);
  
  this.textContent = (arg_type === 'percent')?(Math.round(arg_val*100) + '%'):(arg_val.toFixed(2));
  update_all(arg_val);
}, false);

el_arg_incr.addEventListener('click', function() {
  arg_val += .01;
  
  if(arg_val > 1) {
    arg_val = 1;
    return;
  }
  
  update_arg_val(arg_val);
  update_all(arg_val);
}, false);

el_arg_decr.addEventListener('click', function() {
  arg_val -= .01;
  
  if(arg_val < 0) {
    arg_val = 0;
    return;
  }
  
  update_arg_val(arg_val);
  update_all(arg_val);
}, false);

el_arg_modif.addEventListener('input', function() {
  arg_val = 1*this.value;
  update_all(arg_val, 1);
}, false);
              
            
!
999px

Console