Renders the given text at the given (x, y) coordinates, ensuring that the text isn’t wider than maxWidth (if specified), using the current font, textAlign, and textBaseline values.
Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntaxvar object = object.fillText(text, x, y, maxWidth);
Parameters text
The text characters to paint on the canvas.
xThe horizontal coordinate to start painting the text at, relative to the canvas.
yThe vertical coordinate to start painting the text, relative to the canvas.
maxWidth(Optional)
The maximum possible text width. If the value is less than the width property, the text is scaled to fit.
Return ValueReturns an object of type DOM NodeDOM Node
Type: HRESULT
This method can return one of these values.
Return code Description S_OK The operation completed successfully. SecurityError The current font is not of the same origin or domain as the document that owns the canvas element. ExamplesThis example sets a font for upcoming text, then places the value of a string variable onto the canvas.
<canvas id="myCanvas" width="300" height="150" style="border:1px solid blue;"></canvas>
<p>. . .</p>
<script>
var can = document.getElementById("myCanvas");
var ctxt = can.getContext("2d");
var text = "Hello, world.";
ctxt.font="24px Verdana";
ctxt.fillText(text, 50, 75);
</script>
Related specifications
Microsoft Developer Network: Windows Internet Explorer API reference Article
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.4