QuickDevGuide

Home › HTML

Canvas & SVG Graphics — HTML

The <canvas> element is a powerful blank slate for drawing graphics via JavaScript. Unlike retained-mode HTML elements, Canvas is an immediate-mode system — you tell the browser what to paint, pixel by pixel, and it forgets immediately. Getting Started Define the element in HTML and access its context in JavaScript via getContext('2d'). The coordinate system starts at the top-left corner (0,0): X increases rightward, Y increases downward. Core Drawing Techniques Basic Shapes: fillRect() draws solid rectangles, strokeRect() draws outlines, clearRect() acts as an eraser. Complex Paths: beginPath() starts a path, moveTo() lifts the "pen," lineTo() draws lines, arc() draws curves/circles, then fill() or stroke() renders it. State & Animation ctx.save() pushes current state (color, rotation)…

Key Takeaways