This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

emHeightAscent

Summary

The distance from the horizontal line indicated by the textBaseline attribute to the top of the em square in the line box, in CSS pixels; positive numbers indicating that the given baseline is below the top of the em square (so this value will usually be positive). Zero if the given baseline is the top of the em square; half the font size if the given baseline is the middle of the em square.

Property of apis/canvas/TextMetricsapis/canvas/TextMetrics

Syntax

Note: This property is read-only.

var result = TextMetrics.emHeightAscent;

Return Value

Returns an object of type NumberNumber

Examples

<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");
ctxt.font = "24px Arial";
var txt = "Hello world!"
ctxt.fillText(txt, 10, 75);
var mets = ctxt.measureText(txt);
alert("emHeightAscent: " + mets.emHeightAscent);
//Use with caution: may return "undefined" even in supported browsers
</script>

Related specifications

W3C HTML Canvas 2D Specification
W3C Candidate Recommendation

Attributions