<canvas>

Embedded

Provides a drawing surface for JavaScript-powered graphics, charts, animations, and game rendering.

Common Attributes

widthheight

Example

<canvas id="myCanvas" width="400" height="300"></canvas>
<script>
  const ctx = document.getElementById('myCanvas').getContext('2d');
  ctx.fillRect(10, 10, 100, 100);
</script>

About the <canvas> Element

The <canvas> HTML element belongs to the Embedded category of HTML elements. Provides a drawing surface for JavaScript-powered graphics, charts, animations, and game rendering. Understanding when and how to use this element is essential for building well-structured, accessible, and SEO-friendly web pages.

The <canvas> element requires both an opening <canvas> and closing </canvas> tag. Content placed between these tags becomes the element's children. This element is part of the current HTML Living Standard and is supported in all modern browsers including Chrome, Firefox, Safari, and Edge.

Proper use of semantic HTML elements like <canvas> improves document structure, helps screen readers interpret content correctly, and provides signals to search engines about the purpose of different sections of your page. This leads to better accessibility scores, improved SEO rankings, and more maintainable code.

Related Elements