Publish in HTML Tutorial el 23/05/2025 17:40
The HTML <canvas>
element provides a resolution-dependent bitmap canvas that can be used for rendering graphs, game graphics, art, or other visual images on the fly using JavaScript. It's essentially a drawable region defined in HTML code with height and width attributes.
Key characteristics of <canvas>
:
Here's how to define a basic canvas element in HTML:
To actually draw on the canvas, you need to get its rendering context:
This example shows how to draw a simple filled rectangle on a canvas.
This example demonstrates how to draw a circle using the arc method.
Canvas can also render text with various styling options.
This example shows a basic animation of a bouncing ball using JavaScript.
This example demonstrates how to load and draw an image onto the canvas.
requestAnimationFrame
instead of setInterval
or setTimeout
.clearRect(0, 0, width, height)
to clear the canvas between frames.ctx.save()
and ctx.restore()
to manage the drawing state.The <canvas>
element is supported in all modern browsers, including:
The <style> HTML element contains style information for a document, or part of a document. ...
The <strong> element is used to indicate that its content has strong importance, seriousnes...
The <span> element is an inline container used to mark up a part of a text or document. Unl...
The <source> element is used to specify multiple media resources for media elements like &l...
The <small> element is used to represent side-comments and small print, typically for discl...
HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...