Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <h1 class="title">Homage to the Square</h1>
  <p>
    Based on the series of paintings by
    <a class="link" href="https://en.wikipedia.org/wiki/Josef_Albers">Josef Albers</a>.
  </p>
  <p>
    <a class="link" href="https://codepen.io/ramonmcros/pen/yNEeNo">CodePen</a> || <a class="link" href="https://github.com/ramonmcros/homage-to-the-square" target="_blank">GitHub</a>
  </p>
  <canvas id="homage" width="632" height="632"></canvas>
  <form class="controls">
    <fieldset class="group" action="index.html" method="post">
      <legend>First Square</legend>
      <label for="first-hue">Hue</label>
      <input type="range" id="first-hue" name="first-hue" min="0" value="7" max="360">
      <label for="first-saturation">Saturation</label>
      <input type="range" id="first-saturation" name="first-saturation" min="0" value="66" max="100">
      <label for="first-lightness">Lightness</label>
      <input type="range" id="first-lightness" name="first-lightness" min="0" value="82" max="100">
    </fieldset>
    <fieldset class="group" action="index.html" method="post">
      <legend>Second Square</legend>
      <label for="second-hue">Hue</label>
      <input type="range" id="second-hue" name="second-hue" min="0" value="21" max="360">
      <label for="second-saturation">Saturation</label>
      <input type="range" id="second-saturation" name="second-saturation" min="0" value="98" max="100">
      <label for="second-lightness">Lightness</label>
      <input type="range" id="second-lightness" name="second-lightness" min="0" value="68" max="100">
    </fieldset>
    <fieldset class="group" action="index.html" method="post">
      <legend>Third Square</legend>
      <label for="third-hue">Hue</label>
      <input type="range" id="third-hue" name="third-hue" min="0" value="27" max="360">
      <label for="third-saturation">Saturation</label>
      <input type="range" id="third-saturation" name="third-saturation" min="0" value="99" max="100">
      <label for="third-lightness">Lightness</label>
      <input type="range" id="third-lightness" name="third-lightness" min="0" value="58" max="100">
    </fieldset>
    <fieldset class="group" action="index.html" method="post">
      <legend>Fourth Square</legend>
      <label for="fourth-hue">Hue</label>
      <input type="range" id="fourth-hue" name="fourth-hue" min="0" value="23" max="360">
      <label for="fourth-saturation">Saturation</label>
      <input type="range" id="fourth-saturation" name="fourth-saturation" min="0" value="99" max="100">
      <label for="fourth-lightness">Lightness</label>
      <input type="range" id="fourth-lightness" name="fourth-lightness" min="0" value="57" max="100">
    </fieldset>
    <a href="#" id="save" class="save">Save</a>
  </form>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Droid+Sans:400,700);

$cloud: #c5c5d0;
$dark-cloud: darken($cloud, 40%);
$darkest-cloud : darken($dark-cloud, 20%);

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

body {
  color: $dark-cloud;
  font-family: 'Droid Sans', sans-serif;
  font-size: 18px;
  padding: 0 24px;
}

p {
  text-align: center;
}

.link {
  text-decoration: none;
  color: $darkest-cloud;

  &:hover {
    border-bottom: 2px solid $darkest-cloud;
    padding-bottom: 1px;
  }
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  width: 50%;
  padding: 40px 0 40px 15px;

  @media all and (max-width: 900px) {
    width: 100%;
    padding: 40px 0;
  }

  @media all and (max-width: 500px) {
    padding: 15px 0;
    font-size: 16px;
  }
}

.title {
  display: block;
  width: 100%;
  font-size: 48px;
  text-align: center;
  margin-bottom: 30px;
}

.group {
  border: none;
  padding: 15px;
  width: 50%;
  margin: 0 0 10px;

  legend {
    font-weight: bold;
    text-align: center;
    width: 100%;
  }

  input {
    display: block;
  }

  label {
    display: block;
    text-align: center;
    margin-top: 15px;

    &[for*="hue"] {
      margin-top: 0;
    }
  }
}

#homage {
  width: 50%;
  padding: 40px 15px;
  float: left;

  @media all and (max-width: 900px) {
    width: 100%;
    float: none;
    max-width: 632px;
    margin: 0 auto;
    display: block;
  }

  @media all and (max-width: 500px) {
    padding: 15px 0;
  }
}

.save {
  margin: 30px 0;
  color: white;
  background-color: $dark-cloud;
  padding: 10px 25px;
  text-decoration: none;
  text-align: center;

  &:hover {
    background: $darkest-cloud;
  }

  @media all and (max-width: 500px) {
    margin-top: 0;
  }
}

/* *
 * Sliders
 */

input[type=range] {
  -webkit-appearance: none;
  width: 100%; /* Specific width is required for Firefox. */
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
}

input[type=range]:focus {
  outline: none;
}

input[type=range]::-ms-track {
  cursor: pointer;
  background: transparent;
  border-color: transparent;
  color: transparent;
  margin: 10px 0;
}

input[type=range]::-webkit-slider-thumb {
  height: 9px;
  width: 9px;
  border-radius: 50%;
  background: $dark-cloud;
  margin-top: -3px;

}

input[type=range]:active::-webkit-slider-thumb {
  height: 15px;
  width: 15px;
  margin-top: -6px;
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: $cloud;
  margin: 10px 0;
}

input[type=range]:focus::-webkit-slider-runnable-track {
  background: $cloud;
}

input[type=range]::-moz-range-thumb {
  height: 9px;
  width: 9px;
  border-radius: 50%;
  background: $dark-cloud;
  border: none;
}

input[type=range]:active::-moz-range-thumb {
  height: 15px;
  width: 15px;
}

input[type=range]::-moz-range-track {
  background-color: $cloud;
  height: 3px;
}

input[type=range]::-ms-thumb {
  height: 9px;
  width: 9px;
  background: $dark-cloud;
  border: none;
  border-radius: 50%;
}

input[type=range]::-ms-track {
  width: 100%;
  height: 3px;
  cursor: pointer;
  background: $cloud;
}

input[type=range]::-ms-fill-lower {
  background: $cloud;
}
input[type=range]:focus::-ms-fill-lower {
  background-color: $cloud;
}
input[type=range]::-ms-fill-upper {
  background-color: $cloud;
}
input[type=range]:focus::-ms-fill-upper {
  background-color: $cloud;
}

              
            
!

JS

              
                window.onload = function() {
  var homage = document.getElementById('homage');
  context = homage.getContext('2d');

  // First square HSL color variables
  var firstHue = document.getElementById('first-hue');
  var firstSaturation = document.getElementById('first-saturation');
  var firstLightness = document.getElementById('first-lightness');
  // Second square HSL color variables
  var secondHue = document.getElementById('second-hue');
  var secondSaturation = document.getElementById('second-saturation');
  var secondLightness = document.getElementById('second-lightness');
  // Third square HSL color variables
  var thirdHue = document.getElementById('third-hue');
  var thirdSaturation = document.getElementById('third-saturation');
  var thirdLightness = document.getElementById('third-lightness');
  // Fourth square HSL color variables
  var fourthHue = document.getElementById('fourth-hue');
  var fourthSaturation = document.getElementById('fourth-saturation');
  var fourthLightness = document.getElementById('fourth-lightness');

  var save = document.getElementById('save');

  var passHSL = function(hue, saturation, lightness) {
    return 'hsl(' + hue.value + ', ' + saturation.value + '%, ' + lightness.value + '%)';
  };

  function firstSquare() {
    var colorFirst = passHSL(firstHue, firstSaturation, firstLightness);
    context.fillStyle = colorFirst;
    context.fillRect(0, 0, 632, 632);
    firstHue.addEventListener('input', firstSquare);
    firstSaturation.addEventListener('input', firstSquare);
    firstLightness.addEventListener('input', firstSquare);
    secondSquare();
  }

  function secondSquare() {
    var colorSecond = passHSL(secondHue, secondSaturation, secondLightness);
    context.fillStyle = colorSecond;
    context.fillRect(62, 96, 508, 508);
    secondHue.addEventListener('input', secondSquare);
    secondSaturation.addEventListener('input', secondSquare);
    secondLightness.addEventListener('input', secondSquare);
    thirdSquare();
  }

  function thirdSquare() {
    var colorThird = passHSL(thirdHue, thirdSaturation, thirdLightness);
    context.fillStyle = colorThird;
    context.fillRect(124, 192, 384, 384);
    thirdHue.addEventListener('input', thirdSquare);
    thirdSaturation.addEventListener('input', thirdSquare);
    thirdLightness.addEventListener('input', thirdSquare);
    fourthSquare();
  }

  function fourthSquare() {
    var colorFourth = passHSL(fourthHue, fourthSaturation, fourthLightness);
    context.fillStyle = colorFourth;
    context.fillRect(186, 288, 260, 260);
    fourthHue.addEventListener('input', fourthSquare);
    fourthSaturation.addEventListener('input', fourthSquare);
    fourthLightness.addEventListener('input', fourthSquare);
  }

  firstSquare();

  save.addEventListener('click', function(evt) {
    this.href = homage.toDataURL();
    this.download = 'homage-to-the-square.png';
  }, false);

};

              
            
!
999px

Console