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

              
                <html>
<head>
<script type="text/javascript">
//create the canvas element
var myCanvas = document.createElement("canvas");

//set the canvas width and height
myCanvas.width=100;
myCanvas.height=100;

//get the 2-dimensional drawing context
var ctx = myCanvas.getContext("2d");
//first we clear the canvas
ctx.clearRect(0,0,100,100);
//setup the palette array
var grayPalette = ["#aaaaaa","#bbbbbb","#cccccc","#dddddd","#eeeeee"];

//create 10x10 squares
for (i=0;i<10;i++){
 for(j=0;j<10;j++){
  //indicate when starting drawing a rectangle
  ctx.beginPath();
  ctx.rect(0+10*j,0+10*i,10,10);

  //choose a random color from the palette
  var randomColorIndex = 
    Math.round(Math.random() * (grayPalette.length-1));
  ctx.fillStyle = grayPalette[randomColorIndex];

  //fill the rectangle with the selected color
  ctx.fill();

  //draw a white border for the rectangle
  ctx.strokeStyle = "#ffffff";
  ctx.stroke();

  //indicating when finished drawing the rectangle
  ctx.closePath();
 }
}

//this will run when the document has finished loading
function setDynamicBackground(){
  //generate the image from the canvas
  var imageDataURL = myCanvas.toDataURL();

  //set the dynamic image as the background
  document.body.style.background = 
   "transparent url('"+imageDataURL+"') repeat";
}
</script>
</head>
<body onload="setDynamicBackground()">
<a href="http://www.coding-dude.com/wp/web-design/create-dynamic-backgrounds-website-using-html5-canvas/">Canvas Dynamic Background</a>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console