
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to draw a star by using canvas HTML5?
Drawing on the HTML canvas is to be done with JavaScript. Use the HTML DOM Method getElementById() and getContext() before drawing on the canvas. To draw a star in HTML, use the canvas element.
With canvas, use the lineTo() method to draw a star. The lineTo() method includes x and y parameter values, which positions the lines to help you in drawing.
To draw canvas on HTML document:
Example
You can try to run the following code to draw a star using HTML5 canvas
<!DOCTYPE HTML> <html> <head> <title>HTML5 Canvas Tag</title> </head> <body> <canvas id="newCanvas" width="300" height="250"></canvas> <script> var canvas = document.getElementById('newCanvas'); var ctx = canvas.getContext('2d'); ctx.fillStyle = "blue"; ctx.beginPath(); ctx.moveTo(108, 0.0); ctx.lineTo(141, 70); ctx.lineTo(218, 78.3); ctx.lineTo(162, 131); ctx.lineTo(175, 205); ctx.lineTo(108, 170); ctx.lineTo(41.2, 205); ctx.lineTo(55, 131); ctx.lineTo(1, 78); ctx.lineTo(75, 68); ctx.lineTo(108, 0); ctx.closePath(); ctx.fill(); </script> </body> </html>
Output
- Related Articles
- How to draw lines using HTML5 Canvas?
- How to draw a star in HTML5 SVG?
- How to draw a rectangle on HTML5 Canvas?
- How to draw grid using HTML5 and canvas or SVG?
- How to draw a Bezier Curve with HTML5 Canvas?
- How to draw a quadratic curve on HTML5 Canvas?
- How to draw an oval in HTML5 canvas?
- How to draw large font on HTML5 Canvas?
- Draw a shadow with HTML5 Canvas
- Draw Bezier Curve with HTML5 Canvas
- How to draw an SVG file on an HTML5 canvas?
- Load image from url and draw to HTML5 Canvas
- HTML5 drawImage() method to draw image onto the canvas
- Draw part of an image inside HTML5 canvas
- Properties to create text using HTML5 Canvas

Advertisements