HTML canvas font attribute
Example
Write a 30-pixel text on the canvas using the font "Arial":
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Hello World",10,50);
Try it »
Browser support





Internet Explorer 9, Firefox, Opera, Chrome and Safari support the font attribute.
**Note:** Internet Explorer 8 and earlier versions do not support
Definition and Usage
The font attribute sets or returns the current font properties of the text content on the canvas.
The font attribute uses the same syntax as the CSS font attribute .
| Default value: | 10px sans-serif |
|---|---|
| JavaScript syntax: | context.font="italic small-caps bold 12px arial"; |
Attribute values
| Value | Description |
|---|---|
| font-style | Specifies the font style. Possible values:
|
- normal
- small-caps
- normal
- bold
- bolder
- lighter
- 100
- 200
- 300
- 400
- 500
- 600
- 700
- 800
- 900
Canvas object