Favorites

CSS <box-edge> Data Type

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

The <box-edge> data type is a keyword that names an edge of the box model, such as content-box, padding-box, border-box or margin-box.

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 <box-edge> CSS data type represents a keyword that refers to one of the edges of an element's box model, such as the content edge, the padding edge, the border edge or the margin edge. Properties use it to decide which area of the box a background, mask, clipping path or transform should be measured from. Typical properties that accept a <box-edge> value (or a subset of it) include background-clip, background-origin, box-sizing, clip-path, mask-clip, mask-origin, shape-outside and transform-box.

For HTML elements, the four familiar edges are content-box, padding-box, border-box and margin-box, moving outward from the content. For SVG elements, which have no CSS box model of their own, three extra keywords are available: fill-box (the object bounding box), stroke-box (the stroke bounding box) and view-box (the nearest SVG viewport). When an SVG keyword is used on an HTML element, the browser maps it to a sensible HTML equivalent, usually content-box or border-box.

The specification also groups these keywords into smaller sets for properties that only accept some of them: <visual-box> (content, padding and border), <layout-box> (adds margin-box), <paint-box> (adds fill-box and stroke-box) and <coord-box> (adds view-box). Not every property accepts every keyword, so check the property you are using.

Examples:

/* Paint the background only behind the content */
.card {
  padding: 20px;
  border: 8px dashed #334155;
  background-color: #38bdf8;
  background-clip: content-box;
}

/* Position a background image from the border edge */
.hero {
  background-image: url("pattern.png");
  background-origin: border-box;
}

/* Clip to the padding area with rounded corners */
.avatar {
  clip-path: inset(0 round 12px) padding-box;
}

/* Rotate an SVG shape around its own centre */
svg rect {
  transform-box: fill-box;
  transform-origin: center;
}

Understanding <box-edge> makes it easier to predict where backgrounds stop, how masks are positioned, and which point an SVG shape rotates around.

Interactive Demo

Content area
Demo Code
HTML Code
<div class="demo-element">Content area</div>
CSS Code
.demo-element {
	width: 200px;
	padding: 20px;
	border: 12px dashed rgb(27 31 59 / 50%);
	background: #f72585 linear-gradient(135deg, #4361ee, #f72585);
	background-repeat: no-repeat;
	color: #fff;
	font-weight: bold;
	background-clip: border-box;
}

Syntax

<box-edge> = content-box | padding-box | border-box | margin-box | fill-box | stroke-box | view-box

Values

  • content-boxRefers to the content edge of the box, the area that holds the element's content.
  • padding-boxRefers to the padding edge of the box, which includes the content and the padding.
  • border-boxRefers to the border edge of the box, which includes the content, padding and border.
  • margin-boxRefers to the margin edge of the box, which includes the content, padding, border and margin.
  • fill-boxRefers to the object bounding box of an SVG element. On HTML elements it is treated as content-box.
  • stroke-boxRefers to the stroke bounding box of an SVG element. On HTML elements it is treated as content-box.
  • view-boxRefers to the nearest SVG viewport. On HTML elements it is treated as border-box.

Example

<div class="wrap">
<h1>CSS &lt;box-edge&gt; examples</h1>
<div class="grid">
<div class="box border-box"><span>border-box</span></div>
<div class="box padding-box"><span>padding-box</span></div>
<div class="box content-box"><span>content-box</span></div>
</div>
<p class="note">Each box uses background-clip with a different &lt;box-edge&gt; keyword.</p>
</div>
/* Demonstrates  keywords using background-clip */
* { box-sizing: border-box; }

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

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

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.box {
  padding: 24px;
  border: 10px dashed rgba(15, 23, 42, 0.55);
  border-radius: 12px;
  background-color: #38bdf8;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 14px;
  font-weight: 700;
}

.box span {
  background: #fff;
  padding: 4px 8px;
  border-radius: 6px;
}

.border-box { background-clip: border-box; }
.padding-box { background-clip: padding-box; }
.content-box { background-clip: content-box; }

.note {
  margin-top: 14px;
  font-size: 13px;
  color: #475569;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS box-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.