Favorites

CSS <text-edge> Data Type

<text-edge>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

The <text-edge> data type is a pair of font metrics, such as cap alphabetic, that set the top and bottom edges of text for text-box-edge.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The <text-edge> CSS data type represents a pair of font metrics that define where the top (over) edge and bottom (under) edge of a line of text should be. It is used by the text-box-edge property and the text-box shorthand, which trim the extra space that fonts normally add above and below the letters.

By default, a line of text is as tall as the font's ascent and descent, which includes room for accents and descenders. This is why text inside a button or badge often looks as if it has more space above it than below, even with equal padding. With <text-edge> you can tell the browser to use a tighter metric instead, such as the cap height (cap, the top of capital letters), the x-height (ex, the top of lowercase letters such as "x") or the alphabetic baseline (alphabetic, the line letters sit on). For CJK text, the ideographic and ideographic-ink keywords use the edges of the ideographic em box or ink.

The first keyword sets the over edge and the optional second keyword sets the under edge. Not every keyword is valid for both edges: cap and ex only make sense for the over edge, and alphabetic only for the under edge. If only one keyword is given, it is used for both edges where possible; otherwise the missing edge uses text. The trimming itself is switched on with text-box-trim, which chooses whether to trim the start, the end or both sides of the block.

Examples:

/* Optically centred label inside a button */
.button {
  padding: 12px 20px;
  text-box: trim-both cap alphabetic;
}

/* Align a large heading's capitals with the top of an image */
h1 {
  text-box-trim: trim-start;
  text-box-edge: cap;
}

/* Use the x-height for lowercase-only text */
.tag {
  text-box: trim-both ex alphabetic;
}

Using <text-edge> values gives designers precise control over vertical rhythm, so spacing in code matches the spacing in design tools.

Interactive Demo

Hxpg

Demo Code
HTML Code
<p class="demo-element">Hxpg</p>
CSS Code
.demo-element {
	display: inline-block;
	margin: 24px 0;
	padding: 0 8px;
	font-size: 54px;
	line-height: 1.4;
	background: #e7ecff;
	color: #1b1f3b;
	outline: 2px solid #4361ee;
	text-box: normal;
}

Syntax

<text-edge> = [ text | cap | ex | ideographic | ideographic-ink ] [ text | alphabetic | ideographic | ideographic-ink ]?

Values

  • textUses the text-over baseline (for the over edge) or text-under baseline (for the under edge) of the font, which corresponds to its ascent and descent. This is the default.
  • capUses the cap-height baseline, the top of capital letters. Valid for the over edge only.
  • exUses the x-height baseline, the top of lowercase letters. Valid for the over edge only.
  • alphabeticUses the alphabetic baseline, the line on which most Latin letters sit. Valid for the under edge only.
  • ideographicUses the ideographic-over or ideographic-under baseline, the edges of the ideographic em box.
  • ideographic-inkUses the ideographic-ink-over or ideographic-ink-under baseline, the edges of the ink of ideographic characters.

Example

<div class="wrap">
<h1>CSS &lt;text-edge&gt; examples</h1>
<div class="row">
<div class="example">
<span class="button">Hello</span>
<div class="label">normal (text text)</div>
</div>
<div class="example">
<span class="button trim-cap">Hello</span>
<div class="label">trim-both cap alphabetic</div>
</div>
<div class="example">
<span class="button trim-ex">hello</span>
<div class="label">trim-both ex alphabetic</div>
</div>
</div>
</div>
/* Compares untrimmed text with  trimming */
* { box-sizing: border-box; }

body {
  margin: 24px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  background: #f5f7fb;
  color: #102a43;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
}

h1 {
  font-size: 20px;
  margin: 0 0 16px;
}

.row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.example {
  text-align: center;
}

.label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: #486581;
  margin-top: 8px;
}

.button {
  display: inline-block;
  padding: 14px 22px;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  background: #2563eb;
  border-radius: 10px;
  /* dashed lines show the padding edges */
  outline: 1px dashed #93c5fd;
  outline-offset: -14px;
}

.trim-cap {
  text-box: trim-both cap alphabetic;
}

.trim-ex {
  text-box: trim-both ex alphabetic;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS text-edge data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.

This data type is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.