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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <h1>Lab: Pixel Art Maker</h1>
<h2>Choose Grid Size</h2>
<form id="sizePicker">
  Grid Height:
  <input type="number" id="input_height" name="height" min="1" value="1"><br>
  Grid Width:
  <input type="number" id="input_width" name="width" min="1" value="1"><br>
  <input type="submit">
</form>

<h2>Pick A Color</h2>
<input type="color" id="colorPicker">
<h2>Design Canvas</h2>

<table id="pixel_canvas"></table>


              
            
!

CSS

              
                * {box-sizing:border-box; font-family:arial; color:#555;}

body {text-align: center; border:4px solid #4CAF50; min-height:97vh; padding-bottom:20px;}

h1 {font-family: Monoton; font-size: 70px; margin: 0.2em; background: #4CAF50; color: #fff;  border-radius:5px;}
h2 {margin: 1em 0 0.25em;}
h2:first-of-type {margin-top: 0.5em;}

table,
tr,
td {border: 1px solid black;}
table {border-collapse: collapse; margin: 0 auto;}
tr {height: 20px;}
td {width: 20px;}

input[type=number] {width: 6em; margin:0.5em;}
input[type=submit] {background: #4CAF50; color: #fff; border:0; padding:7px 20px; font-size:1.1em; border-radius:5px; margin:0.5em;}

              
            
!

JS

              
                function makeGrid() {

  //Get nb of rows and cols input
  var rows = $("#input_height").val();
  var cols = $("#input_width").val();

  //Get table
  var table = $("#pixel_canvas");

  //Reset to empty table --- in case one already created
  table.children().remove();

  //Create rows
  for (var i = 0; i < rows; i++) {
    table.append("<tr></tr>");
    //Create cols
    for (var j = 0; j < cols; j++) {
      table.children().last().append("<td></td>");
    }
  }

  //Listen for cell clicks
  table.on("click", "td", function() {
    //Get color from color picker
    var color = $("input[type='color']").val();
    //Apply color to cell
    $(this).attr("bgcolor", color);
  });
}

// Listen for button clicks to trigger makeGrid()
$("input[type='submit']").click(function(e) {
  e.preventDefault(); //Required to avoid submit and page reload
  makeGrid();
});

              
            
!
999px

Console