Canvas Draw Arc

What You’ll Learn
The canvas arc() method lets you draw circular arcs (including full circles). You control center, radius, start & end angles, and whether it draws anticlockwise.
Angles are measured in radians, where \(2\pi\) is a full circle.
⚡ Quick Reference
ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);x, yArc center point in canvas pixels
radiusDistance from center to arc
radiansUse degrees × (Math.PI / 180)
anticlockwisetrue draws counterclockwise
👀 Live Preview — Arc Controls
Adjust the angles and radius to see how ctx.arc() behaves. This preview also shows the center point and start/end markers.
Remember: canvas 0 radians points to the right (3 o’clock). Positive angles move clockwise unless you set anticlockwise to true.
Draw a Semicircle (Stroke)
This matches the classic beginner example: a half-circle from 0 to \(\pi\) radians.
<canvas id="myCanvas" width="240" height="180"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
// Draw a red arc (semicircle)
ctx.beginPath();
ctx.arc(120, 90, 60, 0, Math.PI, false);
ctx.strokeStyle = 'red';
ctx.lineWidth = 3;
ctx.stroke();
</script>🧠 How it works
The arc is centered at (120, 90) with radius 60. It starts at 0 radians (right side) and ends at \(\pi\) radians (left side), producing a semicircle outline.
Draw a Filled Pie Slice
To create a sector (pie slice), connect the arc back to the center and fill the path.
const cx = 150, cy = 110, r = 80;
const start = 20 * (Math.PI / 180);
const end = 120 * (Math.PI / 180);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.arc(cx, cy, r, start, end, false);
ctx.closePath();
ctx.fillStyle = '#2563eb';
ctx.fill();
ctx.strokeStyle = '#0f172a';
ctx.lineWidth = 2;
ctx.stroke();💡 Best Practices
Do
- Call
beginPath()before each separate arc/path - Convert degrees to radians with
deg * (Math.PI / 180) - Use
stroke()for outlines andfill()for solid shapes - For pie slices,
moveTo()the center thenclosePath() - Use
lineCap = 'round'for smoother arc endpoints
Don’t
- Pass degrees directly (your arc will be tiny or wrong)
- Forget
stroke()/fill()after defining the arc - Expect an arc to show if radius is 0 or angles are identical
- Assume direction is always counterclockwise (default is clockwise)
- Overdraw huge canvases every frame without throttling/profiling
❓ Frequently Asked Questions
stroke() or fill it with fill().deg * (Math.PI / 180).beginPath(), a non-zero radius, different start/end angles, and that you called stroke() or fill().Learn Bezier Curves Next
After arcs, Beziers are the next step for drawing smooth curves and paths.
4 people found this page helpful
