The CanvasRenderingContext2D.textBaseline property of the Canvas 2D API specifies the current text baseline used when drawing text.


ctx.textBaseline = "top" || "hanging" || "middle" || "alphabetic" || "ideographic" || "bottom";


Possible values:

The text baseline is the top of the em square.
The text baseline is the hanging baseline. (Used by Tibetan and other Indic scripts.)
The text baseline is the middle of the em square.
The text baseline is the normal alphabetic baseline. Default value.
The text baseline is the ideographic baseline; this is the bottom of the body of the characters, if the main body of characters protrudes beneath the alphabetic baseline. (Used by Chinese, Japanese, and Korean scripts.)
The text baseline is the bottom of the bounding box. This differs from the ideographic baseline in that the ideographic baseline doesn't consider descenders.

The default value is "alphabetic".


Comparison of property values

This example demonstrates the various textBaseline property values.


<canvas id="canvas" width="550" height="500"></canvas>


const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

const baselines = ['top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'];
ctx.font = '36px serif';
ctx.strokeStyle = 'red';

baselines.forEach(function (baseline, index) {
  ctx.textBaseline = baseline;
  const y = 75 + index * 75;
  ctx.moveTo(0, y + 0.5);
  ctx.lineTo(550, y + 0.5);
  ctx.fillText('Abcdefghijklmnop (' + baseline + ')', 0, y);



Specification Status Comment
HTML Living Standard
The definition of 'CanvasRenderingContext2D.textBaseline' in that specification.
Living Standard

Browser compatibility

BCD tables only load in the browser

See also