A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/wordSpacing below:

CanvasRenderingContext2D: wordSpacing property - Web APIs

CanvasRenderingContext2D: wordSpacing property

Baseline 2025

Newly available

The CanvasRenderingContext2D.wordSpacing property of the Canvas API specifies the spacing between words when drawing text.

This corresponds to the CSS word-spacing property.

Value

The word spacing as a string in the CSS <length> data format. The default is 0px.

The property can be used to get or set the spacing. The property value will remain unchanged if set to an invalid/unparsable value.

Examples

In this example we display the text "Hello World" three times, using the wordSpacing property to modify the spacing in each case. The spacing is also displayed for each case, using the value of the property.

HTML
<canvas id="canvas" width="700"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");

ctx.font = "30px serif";

// Default word spacing
ctx.fillText(`Hello world (default: ${ctx.wordSpacing})`, 10, 40);

// Custom word spacing: 10px
ctx.wordSpacing = "10px";
ctx.fillText(`Hello world (${ctx.wordSpacing})`, 10, 90);

// Custom word spacing: 30px
ctx.wordSpacing = "30px";
ctx.fillText(`Hello world (${ctx.wordSpacing})`, 10, 140);
Result Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3