files/en-us/web/api/canvasrenderingcontext2d/textrendering/index.md
{{APIRef("Canvas API")}}
The CanvasRenderingContext2D.textRendering property of the Canvas API provides information to the rendering engine about what to optimize for when rendering text.
The values correspond to the SVG text-rendering attribute (and CSS {{cssxref("text-rendering")}} property).
A text-rendering hint to the browser engine. This one of:
auto
optimizeSpeed
optimizeLegibility
geometricPrecision
The property can be used to get or set the value.
In this example we display the text "Hello World" using each of the supported values of the textRendering property.
The value is also displayed for each case by reading the property.
<canvas id="canvas" width="700" height="220"></canvas>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
ctx.font = "20px serif";
// Default (auto)
ctx.fillText(`Hello world (default: ${ctx.textRendering})`, 5, 20);
// Text rendering: optimizeSpeed
ctx.textRendering = "optimizeSpeed";
ctx.fillText(`Hello world (${ctx.textRendering})`, 5, 50);
// Text rendering: optimizeLegibility
ctx.textRendering = "optimizeLegibility";
ctx.fillText(`Hello world (${ctx.textRendering})`, 5, 80);
// Text rendering: geometricPrecision
ctx.textRendering = "geometricPrecision";
ctx.fillText(`Hello world (${ctx.textRendering})`, 5, 110);
{{ EmbedLiveSample('Examples', 700, 230) }}
{{Specifications}}
{{Compat}}