font
Summary
The current canvas context font and characteristics, in the manner of the CSS font property.
Property of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntax
var result = CanvasRenderingContext2D.font;
CanvasRenderingContext2D.font = value;
Return Value
Returns an object of type StringString
The font string can consist of any CSS font description and is analogous to the CSS font property. The default font is 10px sans-serif
. Values that are not CSS font values are ignored.
Examples
The following exaple write a sample string in the canvas
function draw() {
var ctx = document.getElementById('MyCanvas').getContext('2d');
ctx.font = "16px Times New Roman";
ctx.fillText("Lorem ipsum", 0, 30);
}
Related specifications
- W3C HTML Canvas 2D Specification
- W3C Candidate Recommendation
Attributions
Microsoft Developer Network: Windows Internet Explorer API reference Article