

- 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 text with strokeText() in HTML5?
To draw a text on the canvas in HTML5, use the strokeText() method. Here’s the syntax of the strokeText() method. It strokes the given text at the given position, which is indicated by the given x and y coordinates. The default color is black.
strokeText(text, x, y [, maxWidth ] )
Here are the parameter values of the strokeText() method −
S. No | Parameter | Description |
1 | Text | The text to be written |
2 | X | x coordinate where the painting starts |
3 | Y | x coordinate where the painting starts |
4 | maxWidth | Maximum allowed width in pixels |
Example
You can try to run the following code to draw a text with strokeText() in HTML5 −
<!DOCTYPE html> <html> <head> <title>HTML5 Canvas strokeText()</title> </head> <body> <canvas id="newCanvas" width="400" height="150" style="border:1px solid #000000;"> </canvas> <script> var c = document.getElementById("newCanvas"); var ctxt = c.getContext("2d"); ctxt.fillStyle = '#00F'; ctxt.font = "20px Georgia"; ctxt.strokeText("Tutorialspoint", 10, 50); ctxt.fillStyle = '#Cff765'; ctxt.font = "30px Verdana"; ctxt.strokeText("Simply Easy Learning!", 10, 90); </script> </body> </html>
- Related Questions & Answers
- How to draw a text with fillText() in HTML5?
- How to draw a line with lineTo() in HTML5?
- How to draw a circle with arc() in HTML5?
- Draw a shadow with HTML5 Canvas
- How to draw a Bezier Curve with HTML5 Canvas?
- How to draw sine waves with HTML5 SVG?
- How to draw an Image with drawImage() in HTML5?
- How to draw a 3D sphere in HTML5?
- How to draw a linear gradient in HTML5?
- How to draw a circular gradient in HTML5?
- How to draw a circle in HTML5 SVG?
- How to draw a rectangle in HTML5 SVG?
- How to draw a line in HTML5 SVG?
- How to draw a polygon in HTML5 SVG?
- How to draw a polyline in HTML5 SVG?
Advertisements