

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to draw a circle in JavaScript?
Following is the code to draw a circle in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .circleCanvas { border: 3px solid #110101; } </style> </head> <body> <h1>Draw a circle in JavaScript</h1> <canvas class="circleCanvas" width="400" height="200"></canvas><br /> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to create a circle in the above canvas element</h3> <script> let canvasEle = document.querySelector(".circleCanvas"); let BtnEle = document.querySelector(".Btn"); BtnEle.addEventListener("click", () => { var circle = canvasEle.getContext("2d"); circle.beginPath(); circle.arc(180, 100, 90, 0, 2 * Math.PI); circle.stroke(); }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Questions & Answers
- How to draw a circle in R?
- How to draw a circle in HTML5 SVG?
- How to draw a hollow circle in SVG?
- Draw a circle using OpenCV function circle()
- How to draw circle in HTML page?
- How to draw a circle with arc() in HTML5?
- How to draw a circle in OpenCV using Java?
- How to draw a circle in OpenCV using C++?
- How to draw a filled circle in OpenCV using Java?
- Draw a circle in using Tkinter Python
- How to draw tick mark with circle background shape in android?
- Draw a circle filled with random color squares on HTML5 canvas
- Circle coordinates to array in JavaScript
- How to calculate the area and perimeter of a circle in JavaScript?
- How to plot a circle in Matplotlib?
Advertisements