CSS Reference ยท Typography
The text-box-edge property
Reference for the CSS text-box-edge property: choose which font metrics (cap height, x-height, baseline, text) mark the edges used by text-box-trim. Partial support.
The text-box-edge property chooses the font metrics that define the top and bottom of a text box when it is trimmed. Instead of the tall box created by line-height, you can aim for the top of capital letters, the top of lowercase letters, or the baseline.
It does not trim anything by itself. It only supplies the target for text-box-trim. Support is partial, so check a compatibility table before using it.
.label { text-box-trim: trim-both; text-box-edge: cap alphabetic; }
Try it
In a supporting browser the pink boxes get progressively tighter at the top: text follows the font's ascent, cap stops at the top of the "H", and ex stops at the top of the "x". Without support, all three look alike.
Syntax
text-box-edge: auto | <text-edge> /* <text-edge> = [ text | cap | ex | ideographic | ideographic-ink ] [ text | alphabetic | ideographic | ideographic-ink ]? */
- Initial value:
auto - Applies to: block containers and inline boxes
- Inherited: yes
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
Uses the browser's default edges for the box. |
text |
The font's own ascent (over) or descent (under) metric. |
cap |
Top edge only: the height of capital letters. |
ex |
Top edge only: the height of lowercase letters such as x. |
alphabetic |
Bottom edge only: the baseline. |
ideographic, ideographic-ink |
Edges suited to CJK text. |
The first keyword sets the top edge, the second the bottom edge. The common recipe cap alphabetic trims from the capital letter top to the baseline.
Usage notes
- Two keywords are clearest. Write both the over and under edge, such as
cap alphabetic, rather than relying on how a single keyword is completed. - Descenders. Trimming to the baseline lets letters like g, p and y hang outside the box. Use
textfor the bottom edge if that bothers you. - Works with trim. Without
text-box-trim(or thetext-boxshorthand), this property changes nothing visible. - Inheritance. The value is inherited, so setting it on a container applies to text boxes inside it.
- Font dependent. Cap height and x-height come from the font file, so the result differs between fonts.
- Fallback. Unsupported browsers ignore the property and keep normal spacing.
Browser support
A recent addition with partial support. Check a compatibility table and treat it as progressive enhancement.
Related
text-boxโ the shorthandtext-box-trimโ which sides to trimline-heightโ source of the extra space- Lesson: Line Height