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


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


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.


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.


      <input name="site" type="radio" value="daverupert" checked></label>
      <input name="site" type="radio" value="cnn">
      <input name="site" type="radio" value="lings"> (top third)

<canvas id="canvas"></canvas>
Ratio = <span id="loadpx"></span>:<span id="totalpx"></span>
Decimal = <span id="decpx"></span>


                div {
  position: absolute;
  color: red;
  font-weight: bold;
  top: 2em;
  right: 1em;
  background: white;
  padding: 1em;


                // From

var canvas = document.getElementById("canvas");
var loadpx = document.getElementById("loadpx");
var totalpx = document.getElementById("totalpx");
var decpx = document.getElementById("decpx");
var ctx = canvas.getContext("2d");
var form = document.querySelector('form');

function getRadioVal(name) {
    var val;
    // get list of radio buttons with specified name
    var radios = form.elements[name];
    // loop through list of radio buttons
    for (var i=0, len=radios.length; i<len; i++) {
        if ( radios[i].checked ) { // radio checked?
            val = radios[i].value; // if so, hold its value in val
            break; // and break out of for loop
    return val; // return value of checked radio or undefined if none checked

function getChecked() {
  var currentChecked = getRadioVal('site');
  var newSrc;
  switch( currentChecked ) {
      case 'daverupert':
        newSrc = '';
      case 'cnn':
        newSrc = '';
      case 'lings':
        newSrc = '';
        newSrc = null;
  var img = document.createElement('img');
  img.crossOrigin = 'anonymous';
  img.src = newSrc;
  img.onload = function() {
    canvas.height = img.height;
    canvas.width = img.width;
    // From
    ctx.drawImage(img, 0, 0, canvas.width, canvas.height);

    var data = ctx.getImageData(0, 0, canvas.width, canvas.height),
        buffer =,
        len = buffer.length,
        // threshold = 127,
        threshold = 191,
        load = 0;
    totalpx.textContent = len;
    for(var i=0; i < len; i += 4) {
        lum = buffer[i] * 0.3 + buffer[i+1] * 0.59 + buffer[i+2] * 0.11;
        lum = lum < threshold ? 0 : 255;
        if(lum === 0) {
        	load += 1;
        buffer[i] = lum;
        buffer[i+1] = lum;
        buffer[i+2] = lum;
    loadpx.textContent = load;
    decpx.textContent = Math.round( (load/len) * 1000 ) / 1000;
    ctx.putImageData(data, 0, 0);    
    delete img;

document.querySelector('form').addEventListener('change', getChecked);