HTML | canvas textBaseline Property
The HTML canvas textBaseline property is used to set or return the baseline of current text. This property is used to set the font baseline alignment in HTML. Basically, this property is used to control the vertical alignment of text to draw on to the canvas.
Syntax:
context.textBaseline="alphabetic|top|hanging|middle|ideographic|bottom";
Property Values:
- alphabetic: This is the default property value. It specifies that the text baseline is the normal alphabetic baseline.
- top: This property is used to specify the text baseline is on the top of the em square.
- Hanging: This property is used to specify the text baseline is the hanging baseline.
- middle: This property is used to specify the text baseline is the middle of the em square.
- ideographic: This property is used to specify the text baseline is the ideographic baseline.
- bottom: This property is used to specify the text baseline is the bottom of the bounding box.
Example 1: This example display the top, middle and ideographic properties.
<!DOCTYPE html> <html> <head> <title> HTML canvas textBaseline Property </title> </head> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <h2>HTML canvas textBaseline Property</h2> <canvas id="GFG" width="300" height="300"> </canvas> <script> var doc_id = document.getElementById('GFG'); var context = doc_id.getContext('2d'); var b = ['top', 'middle', 'ideographic']; context.font = '20px Arial'; context.strokeStyle = 'green'; b.forEach(function (b, index) { context.textBaseline = b; var y = 60 + index * 60; context.beginPath(); context.moveTo(0, y + 1); context.lineTo(550, y + 1); context.stroke(); context.fillText('GeeksforGeeks (' + b + ')', 0, y); }); </script> </center> </body> </html> |

Example 2: This example display the hanging, alphabetic and bottom properties.
<!DOCTYPE html> <html> <head> <title> HTML canvas textBaseline Property </title> </head> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <h2>HTML canvas textBaseline Property</h2> <canvas id="GFG" width="300" height="300"> </canvas> <script> var doc_id = document.getElementById('GFG'); var context = doc_id.getContext('2d'); var b = ['hanging', 'alphabetic', 'bottom']; context.font = '20px Arial'; context.strokeStyle = 'green'; b.forEach(function (b, index) { context.textBaseline = b; var y = 60 + index * 60; context.beginPath(); context.moveTo(0, y + 1); context.lineTo(550, y + 1); context.stroke(); context.fillText('GeeksforGeeks (' + b + ')', 0, y); }); </script> </center> </body> </html> |

Supported Browsers: The browsers supported by HTML canvas textBaseline Property are listed below:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | canvas lineJoin Property
- HTML | canvas fillStyle Property
- HTML | canvas globalAlpha Property
- HTML | canvas textAlign Property
- HTML | canvas lineCap Property
- HTML | canvas strokeStyle Property
- HTML | canvas shadowOffsetX Property
- HTML | canvas shadowBlur Property
- HTML | canvas shadowOffsetY Property
- HTML | canvas shadowColor Property
- HTML | canvas lineWidth Property
- HTML | canvas font Property
- HTML | canvas miterLimit Property
- HTML | canvas ImageData data Property
- HTML | canvas ImageData width Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



