2024-09-30 web, development, javascript

How to Draw a Circle With HTML5 Canvas

By O. Wolfson

Draw a circle in a cavas html element using the arc method.

An arc drawn to the HTML5 canvas.

javascript
ctx.arc(canvas.width / 2, canvas.height / 2, 100, 0, Math.PI * 2, false);
ctx.strokeStyle = "blue";
ctx.stroke();

The arc canvas API method takes five (or optionally 6) arguments.

JavaScript
arc( x, y, r, sAngle, eAngle )

x The x-coordinate of the center of the circle, y The y-coordinate of the center of the circle, r The radius of the circle, sAngle The starting angle, in radians (0 is at the 3 o’clock position of the arc’s circle), eAngle The ending angle.

Note that the start / end angle of the arc is expressed in radians. That is why the end angle is 2*PI. 2*PI is equivalent to 360 degrees.

Here is a link to the HTML and JavaScript for this app. View page source to see the code.

This web app may use cookies to enhance the user experience. We do not share, sell, rent, or trade your personal information with any third parties. For more information, please see our privacy policy.