HTML-Canvas- Font -Eigenschaft

❮ HTML-Canvas-Referenz

Beispiel

Schreiben Sie einen 30 Pixel hohen Text mit der Schriftart „Arial“ auf die Leinwand:

Ihr Browser unterstützt den HTML5-Canvastag nicht.

JavaScript:

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

Browser-Unterstützung

Die Zahlen in der Tabelle geben die erste Browserversion an, die die Eigenschaft vollständig unterstützt.

Property
font Yes 9.0 Yes Yes Yes

Definition und Verwendung

Die Font-Eigenschaft legt die aktuellen Schriftarteigenschaften für Textinhalte auf der Leinwand fest oder gibt sie zurück.

Die Font - Eigenschaft verwendet dieselbe Syntax wie die CSS - Font - Eigenschaft .

Standardwert: 10px serifenlos
JavaScript-Syntax: Kontext .font="kursive Kapitälchen fett 12px arial";

Eigenschaftswerte

Values Description Play it
font-style Specifies the font style. Possible values:
  • normal
  • italic
  • oblique
font-variant Specifies the font variant. Possible values:
  • normal
  • small-caps
font-weight Specifies the font weight. Possible values:
  • normal
  • bold
  • bolder
  • lighter
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900
font-size/line-height Specifies the font size and the line-height, in pixels
font-family Specifies the font family
caption Use the font captioned controls (like buttons, drop-downs, etc.)
icon Use the font used to label icons
menu Use the font used in menus (drop-down menus and menu lists)
message-box Use the font used in dialog boxes
small-caption Use the font used for labeling small controls
status-bar Use the fonts used in window status bar

❮ HTML-Canvas-Referenz