Baseline 2023
Newly available
Note: This feature is available in Web Workers.
The read-only fontBoundingBoxAscent
property of the TextMetrics
interface returns the distance from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
attribute, to the top of the highest bounding rectangle of all the fonts used to render the text, in CSS pixels.
A number, in CSS pixels.
ExamplesThe code below shows how you can get the fontBoundingBoxAscent
for some text in a particular font.
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
ctx.font = "25px serif";
const text = "Foo";
const textMetrics = ctx.measureText(text); // returns TextMetrics object
const ascentCssPixels = textMetrics.fontBoundingBoxAscent;
const log = document.getElementById("log");
log.innerText = `fontBoundingBoxAscent: ${ascentCssPixels}`;
The ascent in CSS pixels for the text "Foo" in a 25px serif font is shown below.
Specifications Browser compatibility See alsoRetroSearch 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