260 of 264 menu

font property

The font property sets the font settings when it is drawn on the canvas using the fillText or strokeText methods. The method accepts the same parameters as the CSS font property.

Syntax

context.font = font settings;

Example

Let's draw some text on the canvas with fillText and give it a size of 30px and an Arial type with font:

<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas> let canvas = document.querySelector('#canvas'); let ctx = canvas.getContext('2d'); ctx.font = '30px Arial'; ctx.fillText('Hello world', 30, 50);

:

See also

  • the textAlign property
    that aligns a text horizontally
  • the textBaseline property
    that aligns a text vertically
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline