HTML canvas font attributes
Examples
30 pixels to write a 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);
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 font attributes.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
font property sets or returns the current font properties of the text on the canvas content.
Grammar and font attributes used CSS font properties the same.
Defaults: | 10px sans-serif |
---|---|
JavaScript syntax: | context .font = "italic small-capsbold 12px arial"; |
Property Value
值 | 描述 |
---|---|
font-style | 规定字体样式。可能的值:
|
font-variant | 规定字体变体。可能的值:
|
font-weight | 规定字体的粗细。可能的值:
|
font-size/line-height | 规定字号和行高,以像素计。 |
font-family | 规定字体系列。 |
caption | 使用标题控件的字体(比如按钮、下拉列表等)。 |
icon | 使用用于标记图标的字体。 |
menu | 使用用于菜单中的字体(下拉列表和菜单列表)。 |
message-box | 使用用于对话框中的字体。 |
small-caption | 使用用于标记小型控件的字体。 |
status-bar | 使用用于窗口状态栏中的字体。 |
HTML canvas Reference Manual