W3Schools.com

HTML5 canvas font Attribute

HTML5 track Tag Reference HTML5 canvas reference

Example

Write a 30px high "Hello World" on the canvas, using the font "Arial":

Yor browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Hello World",10,50);

Try it yourself »

Definition and Usage

The font attribute allows you to specify font properties of the text written on the canvas.

The font attribute uses the same syntax as the CSS font property.

Default value: 10px sans-serif
JavaScript syntax: context.font="italic small-caps bold 12px arial";


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The font attribute is supported in all major browsers.


Attribute Values

Values Description Play it
font-style Specifies the font style Play it »
font-variant Specifies the font variant Play it »
font-weight Specifies the font weight Play it »
font-size/line-height Specifies the font size and the line-height Play it »
font-family Specifies the font family Play it »
caption Uses the font that are used by captioned controls (like buttons, drop-downs, etc.) Play it »
icon Uses the font that are used by icon labels Play it »
menu Uses the fonts that are used by dropdown menus Play it »
message-box Uses the fonts that are used by dialog boxes Play it »
small-caption A smaller version of the caption font Play it »
status-bar Uses the fonts that are used by the status bar Play it »

HTML5 track Tag Reference HTML5 canvas reference


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE