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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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

            
              <!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Basic Shapes on Canvas</title>
	<script src="main.js"></script>

</head>
<body>
	  <canvas id="myCanvas" height="500" width="500"></canvas>
</body>
</html>
            
          
!

CSS

            
              #myCanvas {
  border: 2px dotted black;    
}
            
          
!

JS

            
              (() => {
  // get canvas by id
    // get canvas by id
  const canvas = document.querySelector("#myCanvas")
  
  const width = 500
  const height = 500
  
  canvas.width = width
  canvas.height = height
  
  // get 2d context of our canvas
  const ctx = canvas.getContext("2d")
  
  
  const drawFillRect = (x, y, width, height, hexColor, ctx) =>{
    ctx.beginPath()
    ctx.rect(x, y, width, height)
    ctx.fillStyle = hexColor
    ctx.fill()
  }
  
  // background color
  drawFillRect(20, 20, 460, 460, "#FAFCF1", ctx)
  
  
  
  // rectangle at the center
    drawFillRect((width/2)-100, (height/2)-150, 200, 300,  "#F26D85", ctx)
 
  
  // rectangle 2
  drawFillRect(280, 20, 120, 190, "#E97FF4", ctx)
  
  // circle 1
  ctx.beginPath()
  ctx.arc(347, 260, 50, 0, 2*Math.PI)
  ctx.fillStyle = "#9193F6"
  ctx.fill()
  
  // rectangle 3
  drawFillRect(80, 300, 100, 110, "#A4F3F8", ctx)
  
  // triangle
  ctx.beginPath();
  ctx.moveTo(250, 400);
  ctx.lineTo(200, 450);
  ctx.lineTo(300, 450);
  ctx.closePath()
  ctx.fillStyle = "#B6FAC1"
  ctx.fill();
  
  
})()

            
          
!
999px

Console