This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

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