Font styling is a major requirement for web developers and designers to make the page visually appealing. Let us play and learn some font styling tips in a canvas element.
Text can be rendered in a canvas using the fillText() method and font property can be set for styling purpose.
The style available for font are normal, italic, or bold. By default font type is normal.
Font color
fillStyle property can be used to the font color in a cavas.
Font stroke
strokeText() method can be used to create a text stroke and to set the color of that
stroke strokeStyle property of canvas context is used.
Horizontal alignment
To align a text horizontally with respect to a virtual vertical line at the point we created the text
textAlign propertty can be used. Different values that can be assigned to this property
are start, end, left,
center or right.
Vertical alignment
To align a text vertically with respect to a virtual horizontal line at the point we created the text
textBaseline propertty can be used. Different values that can be assigned to this property
are top, middle, bottom,
alphabetic, hanging, or ideographic.