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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>
<head>
    <meta charset=utf-8>

    <title>Pixel Art Maker!</title>
    
    <!-- Google Fonts -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Monoton">
</head>
<body>
    <div class="header">
        <h1>Pixel Art Maker</h1>
    </div>

    <div class="menu">
        <div class="color-picker">
            <h2>Pick A Color</h2>
            <input type="color" value="#7ed6df" id="colorPicker">
        </div>

        <div class="grid-input">
            <h2>Choose Grid Size</h2>
            <form id="sizePicker">
                <input type="number" id="inputWidth" name="width" min="1" placeHolder="Width" value="30">
                <input type="number" id="inputHeight" name="height" min="1" max="75" placeHolder="Height" value="30">
                <button type="button" id="button">Create</button>
                <button type="button" id="reset">Reset</button>
            </form>
        </div>
    </div>

    

    <div class="design-canvas">
        <h2>Design Canvas</h2>
        <table id="pixelCanvas"></table>
    </div>

    <!-- <button type="button" id="save">Save</button> -->

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</body>
</html>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Kelly+Slab|Nixie+One');


body {
    text-align: center;
}

h1 {
    font-family: Monoton;
    font-size: 70px;
    margin: 0.2em;
}

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


/* Custom CSS */


@import url('https://fonts.googleapis.com/css?family=Kelly+Slab|Nixie+One');

body {
	margin: -10px 0 0 0;
	padding: 0;
	font-family: 'Nixie One', cursive;
	font-weight: 100;
	background-color: #c7ecee;
	color: #30336b;
}

input, button {
	padding: 10px;
	font-size: 14px;
	border-radius: 6px
	border: 0;
	text-align: center;
	color: #CCCCCC;
}

#colorPicker {
	width: 35px;
}

.header {
	background-color: #7ed6df;
}

.header h1 {
	font-family: 'Kelly Slab', cursive;
	font-size: 50px;
	padding: 40px;
	color: #130f40;
	font-weight: 10;
}

.menu {
	background-color: #dff9fb;
	margin: -10px 0 0 0;
	padding: 30px;
}

.color-picker {
	display: inline-block;
	margin-right: 20px;
	margin-left: 20px;
}

.grid-input {
	display: inline-block;
	margin-right: 20px;
	margin-left: 20px;
	display:inline-block;
}

.color-picker h2, .grid-input h2 {
	font-size: 18px;
	font-weight: 700;
}

.color-picker h2, .color-picker input, .grid-input h2, .grid-input form {
	display:inline;
}

#button, #reset {
	margin-left: 15px;
	border: 0;
	border-radius: 2px
}

#button {
	background-color: #6ab04c;
}

#reset {
	background-color: #eb4d4b;
}

button {
	font-size: 18px;
	color: #FFFFFF;
}


.design-canvas, #pixelCanvas {
	margin-top: 40px;
}

table, td, tr {
	border: 0;
}

.white {
	background-color: #FFFFFF;
}

.grey {
	background-color: #CCCCCC;
}

#footer {
  height: 100px;
}
            
          
!
            
              // jQuery variables
const sizePicker = $("#sizePicker");
const pixelCanvas = $('#pixelCanvas');

// When size is submitted by the user, call makeGrid()
// This function creates a grid based on the Height and Width inputs
function makeGrid(inputWidth, inputHeight) {
	event.preventDefault();
	let table = "";
	$('.row').remove();

	for (let row = 0; row < inputHeight; row++) {
		table += "<tr class='row'>";
		for (let column = 0; column < inputWidth; column++) {
			if (column % 2 === 0 && row % 2 == 1) {
				table += "<td class='grey'></td>";
			} else if (column % 2 === 1 && row % 2 == 0) {
				table += "<td class='grey'></td>";
			} else {
				table += "<td class='white'></td>";
			}
		}
		table += "</tr>";
	}
	pixelCanvas.append(table);
}

// Resets the canvas to default
function reset(gridWidth, gridHeight) {
	let confirmDelete = confirm('Do you really want to clear your beautiful work?');
	if (confirmDelete) {
    	makeGrid(gridWidth, gridHeight);	
	};
}

$(document).ready(function() {
	// Variables for color and size input
	let gridWidth = sizePicker.find("input[name='height']").val();//$(inputWidth);
	let gridHeight = sizePicker.find("input[name='width']").val();//$(inputHeight);
	let gridColor = "#7ed6df";

	// Create initial grid
	makeGrid(gridWidth, gridHeight);

	// Listener for the create/submit button
	// This grabs the width and height from the user and replaces the existing grid
	$('#button').on('click', function() {
    	event.preventDefault();

    	gridHeight = sizePicker.find("input[name='width']").val();//$(inputHeight);
		gridWidth = sizePicker.find("input[name='height']").val();//$(inputWidth);

		reset(gridWidth, gridHeight);
	});

	// Picks the color
	$('#colorPicker').on('change', function() {
		gridColor = $(this).val();
	});

	// Calls on the reset function when Reset button is clicked
	$('#reset').on('click', function() {
		reset(30, 30);
	});

	// Uses event delegation so that all tds classes (even ones created after the DOM loads) are affected
	// Changes color to current color when mouse hovers on td
	pixelCanvas.on('mousedown mouseover', 'td', function(event) {
		if(event.buttons == 1){
			$(this).css({'background-color': gridColor});
		}
	});
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console