π What Is box-decoration-break?
The box-decoration-break property controls howbackgrounds, borders, padding, and shadows behave when an element is split across multiple lines, columns, or pages.
Note
β Works with multi-column layouts β Works with page breaks (printing) β Essential for stylizing inline text with backgrounds or borders
π¦ Syntax
box-decoration-break syntax
box-decoration-break: slice | clone;| Value | Description |
|---|---|
| slice | Default. Background/border do NOT repeat. They appear sliced across lines. |
| clone | Each line/fragment receives its own full box with border, padding, and background. |
π Why This Matters?
When text wraps to the next line, browsers normally treat the inline box as a **single continuous decoration**, so backgrounds or borders may look broken. With clone, each wrapped line gets a fresh full box.
π 1. Default Behavior (slice)
slice default
span {
background: yellow;
padding: 4px;
box-decoration-break: slice; /* default */
}The background and padding appear sliced across linesβno repeated borders.
π 2. Clone Decoration for Each Line
Clone style
span.highlight {
background: yellow;
padding: 4px;
border-radius: 4px;
box-decoration-break: clone;
-webkit-box-decoration-break: clone; /* Safari support */
}Each wrapped line looks like separate highlighted blocks. This is commonly used for modern inline highlighting.
π Visual Example
Imagine this text wraps into two lines:
- slice: background is cut in the middle
- clone: each line gets its own full padded box
π 3. Highlighting Inline Quotes or Words
Inline highlight
.highlight {
background: #ffeb3b;
padding: 4px 6px;
box-decoration-break: clone;
-webkit-box-decoration-break: clone;
}Perfect for marking important phrases while maintaining clean wrapping.
π 4. Used in Multi-Column Layouts
Columns example
p {
column-count: 2;
}
mark {
background: lightpink;
box-decoration-break: clone;
}When text breaks across columns, each fragment receives consistent decoration.
π 5. Page Breaks in Printed Documents
Print example
@media print {
.note {
background: #ffff99;
padding: 10px;
box-decoration-break: clone;
}
}Ensures notes remain well-styled even when split across printed pages.
π§ͺ Real-World Use Cases
1οΈβ£ Highlight System (e.g., Notion-like)
Notion-style highlight
.notion-highlight {
background: #ffeaa7;
padding: 2px 4px;
border-radius: 3px;
box-decoration-break: clone;
}2οΈβ£ Stylish Inline Badges
Inline badge
.badge-inline {
background: #6200ea;
color: white;
padding: 3px 6px;
border-radius: 4px;
box-decoration-break: clone;
}3οΈβ£ Callouts Inside Multi-Column Articles
Column callouts
.callout {
background: #c8e6c9;
padding: 6px;
box-decoration-break: clone;
}Keeps styled callouts visually consistent across columns.
β οΈ Common Mistakes
- β Forgetting Safari support β must include -webkit-box-decoration-break
- β Expecting it to work on block-level elements (mainly affects inline fragments)
- β Thinking it affects text splitting β it only affects decoration, not line breaks
Note
π₯ Summary
The box-decoration-break property controls how lines, columns, and page fragments handle backgrounds, borders, and padding. Use clone when you want clean, repeated decoration for wrapped lines β perfect for highlighted text or multi-column layouts.
Learn more βMDN Docs π