CSS <box-edge> Data Type
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.
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
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
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.
Desktop





Tablets & Mobile





