CSS Text

As you might have noticed, while Canvas does a pretty good job of displaying a single line of text, displaying multiline text is another story. We have shown you one possible solution, but something else might be in order in the future. According to the W3C Canvas API specification, there might be a change in the future that opens the door for using CSS on the Canvas:

A future version of the 2D context API may provide a way to render fragments of documents, rendered using CSS, straight to the canvas. This would be provided in preference to a dedicated way of doing multiline layout.

CSS would help developers render text on the Canvas and, at the same time, encourage developers to adopt the Canvas for text-based applications.

Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.