v135 · css
RTL Script Canvas
Canvas lang matters most for scripts where glyph selection, ligature formation, and text direction depend heavily on locale. See Arabic, Hebrew, and Persian rendered side-by-side — once with ctx.lang set and once without. The shaping differences are visible in the glyphs themselves.
checking ctx.lang support…
CanvasRenderingContext2D.lang (Chrome 135) tells the font engine which language is being rendered, so it can pick the right glyphs for characters with locale-specific forms. Arabic and Persian share many code points but differ in some glyph shapes. Hebrew text-rendering can also vary subtly by locale. Without lang, the browser guesses — sometimes wrong.
Script comparison — with vs without ctx.lang
Without ctx.lang (default)
No lang attribute set — browser uses document language or no locale.
With ctx.lang set (Chrome 135)
ctx.lang = locale — correct glyph selection for the target script.
Four RTL scripts at a glance
Code
// Select a script and click Draw