Reference text()

text()

Draws text to the canvas.

The first parameter, str, is the text to be drawn. The second and third parameters, x and y, set the coordinates of the text's bottom-left corner. See textAlign() for other ways to align text.

The fourth and fifth parameters, maxWidth and maxHeight, are optional. They set the dimensions of the invisible rectangle containing the text. By default, they set its maximum width and height. See rectMode() for other ways to define the rectangular text box. Text will wrap to fit within the text box. Text outside of the box won't be drawn.

Text can be styled a few ways. Call the fill() function to set the text's fill color. Call stroke() and strokeWeight() to set the text's outline. Call textSize() and textFont() to set the text's size and font, respectively.

Note: WEBGL mode only supports fonts loaded with loadFont(). Calling stroke() has no effect in WEBGL mode.

Examples

Syntax

text(str, x, y, [maxWidth], [maxHeight])

Parameters

str
String|Object|Array|Number|Boolean:

text to be displayed.

x
Number:

x-coordinate of the text box.

y
Number:

y-coordinate of the text box.

maxWidth
Number:

maximum width of the text box. See rectMode() for other options.

maxHeight
Number:

maximum height of the text box. See rectMode() for other options.

Notice any errors or typos? Please let us know. Please feel free to edit src/typography/loading_displaying.js and open a pull request!

Related References