CSS Portal

CSS text-box-edge Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The text-box-edge property specifies which edge of an element’s text layout box should be used as the reference for alignment, clipping and baseline-related calculations in layout. Rather than describing how text is drawn, it picks the logical or physical edge of the “text box” — the rectangle that the formatting system computes around inline content — that other layout mechanisms use as their anchor. This allows authors to change the reference point used for vertical alignment and overflow clipping independently of metrics such as glyph bounding boxes or leading.

Because it affects the reference used for alignment and line box calculation, text-box-edge interacts closely with typographic and inline layout behavior. For example, changing the box edge can alter how adjacent inline boxes are aligned relative to one another and to the line box, producing different results from simply changing vertical-align or adjusting the element’s line-height. It is especially useful in multilingual and vertical-writing contexts where the meaningful “top” or “start” edge of text differs from Latin horizontal baselines; pairing it with the document’s writing direction and orientation lets you keep alignment consistent across scripts and rotations.

Beyond alignment, the chosen text-box edge can be used as the origin for clipping, hit-testing, and offset calculations (for example when positioning decorations or absolute children relative to inline text). That means changing the reference edge can affect how much of an inline element is visible when overflow is constrained and can shift the perceived position of inline-level positioned descendants. Because it governs a reference point rather than glyph metrics directly, it provides a stable, high-level knob for designers who need predictable alignment and clipping behavior across different fonts, sizes, and writing modes without having to micromanage glyph metrics or the element’s own box model.

Definition

Initial value
auto
Applies to
Block containers and inline boxes
Inherited
no
Computed value
the specified keyword
Animatable
yes
JavaScript syntax
object.style.textBoxedge

Syntax

text-box-edge: start | end | cap | descent | line-edge;

Values

  • start Aligns the text relative to the start edge of the text box (usually the left edge in left-to-right text, and right edge in right-to-left text).
  • end Aligns the text relative to the end edge of the text box (opposite of start).
  • cap Uses the cap height of the font (the height of capital letters) as the reference edge.
  • descent Uses the descent line of the font as the reference edge (the lowest part of the glyph below the baseline).
  • line-edgeAligns the text relative to the edge of the line box itself rather than the font metrics.

Example

<div class="container">
<h2>text-box-edge examples</h2>
<div class="example edge-content">
<p>Content-box edge: The inline text's text-box-edge is set to content-box.</p>
</div>
<div class="example edge-padding">
<p>Padding-box edge: The text-box-edge is set to padding-box.</p>
</div>
<div class="example edge-border">
<p>Border-box edge: The text-box-edge is set to border-box.</p>
</div>
</div>
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: #f3f4f6;
  padding: 24px;
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

.example {
  margin: 16px 0;
  padding: 18px;
  border: 6px solid #2563eb;
  background: #ffffff;
  border-radius: 6px;
}

.example p {
  margin: 0;
  line-height: 1.55;
}

.edge-content p {
  -webkit-text-box-edge: content-box;
  text-box-edge: content-box;
}

.edge-padding p {
  -webkit-text-box-edge: padding-box;
  text-box-edge: padding-box;
}

.edge-border p {
  -webkit-text-box-edge: border-box;
  text-box-edge: border-box;
}

Browser Support

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

This property is supported in some modern browsers, but not all.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!