HTML CSS JavaScript SEO Python Posts Privacy About Contact

HTML Canvas

The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript.

The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript. The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the graphics.

Canvas Example

A canvas is a rectangular area on an HTML page. By default, a canvas has no border and no content.

Preview

Drawing a Line

To draw a straight line on a canvas, use the following methods:

  • moveTo(x,y) - defines the starting point of the line
  • lineTo(x,y) - defines the ending point of the line
Preview