CSS widows Property
The CSS widows property specifies the minimum number of lines from a block of text that must remain at the top of a new page, column, or other fragmentation container.
When a paragraph is divided by a page or column break, the widows property helps prevent a single line from appearing alone at the beginning of the next fragment. It works with the orphans property to improve the readability and appearance of printed documents and multi-column layouts.
widows Syntax
The widows property accepts a positive integer representing the minimum number of lines that should appear at the beginning of a new fragment.
Basic Syntax
.element {
widows: 2;
}
Valid Values
.element {
widows: 1;
}
.element {
widows: 2;
}
.element {
widows: 3;
}
.element {
widows: 4;
}
Any positive integer is syntactically valid. A value of 2 is the initial value.
CSS-Wide Keywords
.element {
widows: initial;
}
.element {
widows: inherit;
}
.element {
widows: unset;
}
.element {
widows: revert;
}
.element {
widows: revert-layer;
}
Invalid Values
.element {
widows: 0;
}
.element {
widows: -2;
}
.element {
widows: 2.5;
}
.element {
widows: 50%;
}
.element {
widows: auto;
}
Zero, negative numbers, decimal values, percentages, and auto are not valid values for this property.
Property Values
| Value | Description |
|---|---|
1 |
Allows a single line to appear at the beginning of a new page or column. |
2 |
Requires at least two lines at the beginning of a new fragment when the constraint can be satisfied. This is the initial value. |
3 |
Requests at least three lines at the beginning of a new fragment. |
4 |
Requests at least four lines at the beginning of a new fragment. |
<integer> |
Any positive integer specifying the minimum number of lines required after a fragmentation break. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | 2 |
| Inherited | Yes |
| Applies to | Block containers |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Value type | Positive integer |
| Specification | CSS Fragmentation Module Level 3 |
Note: The property influences line breaks during fragmentation. It does not control ordinary line wrapping inside a continuous block of text.
How It Works
When text extends beyond the available space on a printed page or in a column, the browser may divide the paragraph into multiple fragments.
The widows property specifies how many lines should remain together at the beginning of the following fragment.
Without Additional Widow Control
If a paragraph extends beyond the bottom of a page, its final line could otherwise appear alone at the top of the next page.
With widows: 3
p {
widows: 3;
}
The browser attempts to place at least three lines from the paragraph at the beginning of the next page or column.
Moving Additional Lines
If only one or two lines would appear in the next fragment, the browser can move additional lines from the previous fragment to satisfy the minimum.
Available Space
The result depends on available space, other fragmentation rules, and the browser's layout engine.
When the Constraint Cannot Be Satisfied
If the paragraph is too short or fragmentation constraints conflict, the browser may relax the minimum to complete the layout.
Important Distinction
The property controls the minimum number of lines after a break, not the exact location of the break.
widows and orphans
The widows and orphans properties work together to control how paragraph lines are distributed across fragmentation boundaries.
The widows Property
Controls the minimum number of lines that must appear at the beginning of the following page or column.
The orphans Property
Controls the minimum number of lines that must remain at the end of the preceding page or column.
Combined Example
p {
widows: 3;
orphans: 3;
}
This requests at least three lines on each side of a break within a paragraph.
Comparison
| Property | Controls | Location |
|---|---|---|
widows |
Minimum lines after a break | Top of the next page or column |
orphans |
Minimum lines before a break | Bottom of the previous page or column |
Short Paragraphs
A paragraph with fewer lines than the combined minimums may not be splittable while satisfying both properties.
Practical Recommendation
Using both properties is generally more effective than using either property alone when formatting printed articles and multi-column documents.
Printed Pages
The widows property is particularly useful when preparing web content for printing.
Print Stylesheet
@media print {
p {
widows: 3;
orphans: 3;
}
}
This requests at least three lines on each side of a page break within a paragraph.
Long Articles
@media print {
article p {
widows: 3;
orphans: 2;
}
}
Documentation
@media print {
.documentation p {
widows: 2;
orphans: 2;
}
}
Page Break Control
The widows property can influence where the browser divides a paragraph, but it does not force a new page.
Related Break Properties
@media print {
h2 {
break-after: avoid;
}
p {
widows: 3;
orphans: 3;
}
}
The break-after declaration requests that a heading remain with the following content, while widows and orphans control paragraph line distribution.
Print Preview
Use the browser's print preview to inspect page breaks and confirm the actual result.
Multi-Column Layouts
The widows property can also influence how text is divided between columns in a multi-column layout.
Two-Column Layout
.article-columns {
columns: 2;
column-gap: 30px;
}
.article-columns p {
widows: 3;
orphans: 3;
}
HTML Example
<div class="article-columns">
<p>A paragraph containing enough text to extend across a column boundary.</p>
<p>Another paragraph containing additional article content.</p>
</div>
Column Fragmentation
When a paragraph crosses a column boundary, the browser attempts to keep the specified minimum number of lines at the beginning of the following column.
Column Balancing
Column balancing can affect where breaks occur. The browser must consider available space and other layout constraints.
Browser Differences
Support for widow and orphan constraints in multi-column layouts can vary. Test the actual layout rather than assuming every browser produces identical results.
When to Use It
Use the property for articles, newsletters, and other text-heavy layouts where paragraphs may cross column boundaries.
Fragmentation Behavior
CSS fragmentation occurs when content is divided across multiple pages, columns, or other fragmentation containers.
Fragmentation Boundaries
The widows property applies when line boxes within a block are divided by a fragmentation boundary.
Minimum Line Count
p {
widows: 4;
}
The browser attempts to retain at least four lines at the beginning of the following fragment.
Not an Exact Line Count
A value of 4 does not mean exactly four lines must appear in the next fragment. More lines may appear.
Interaction With break-inside
.important-paragraph {
break-inside: avoid;
widows: 3;
orphans: 3;
}
The break-inside: avoid declaration requests that the paragraph remain together. If the browser must divide it, widow and orphan constraints may influence the line distribution.
Conflicting Constraints
Browsers may relax fragmentation constraints when they cannot all be satisfied.
Continuous Screen Layouts
In ordinary scrolling content without page or column fragmentation, widows generally has no visible effect.
Inheritance
The widows property is inherited. Descendant block containers normally receive the computed value from their parent unless another declaration overrides it.
Parent Declaration
article {
widows: 3;
}
Paragraphs within the article normally inherit the value.
Override on a Child
article {
widows: 3;
}
article .special-paragraph {
widows: 2;
}
Explicit Inheritance
.child {
widows: inherit;
}
Restore the Initial Value
.element {
widows: initial;
}
This restores the initial value of 2.
Using unset
.element {
widows: unset;
}
Because the property is inherited, unset behaves like inherit.
Practical Consideration
Applying widow control to an article or print container can be more convenient than declaring the property separately on every paragraph.
Practical Examples
Standard Paragraph Control
p {
widows: 2;
}
Keep Three Lines Together
article p {
widows: 3;
}
Combined Widow and Orphan Control
article p {
widows: 3;
orphans: 3;
}
Printed Documentation
@media print {
.documentation {
widows: 3;
orphans: 3;
}
}
Multi-Column Article
.columns {
columns: 2;
column-gap: 24px;
}
.columns p {
widows: 3;
orphans: 2;
}
Newsletter Layout
.newsletter {
columns: 3;
}
.newsletter p {
widows: 2;
orphans: 2;
}
Avoid Splitting Short Content
.short-note {
break-inside: avoid;
}
For short blocks that should remain together, break-inside: avoid may be more appropriate than increasing the widow count.
Print-Only Formatting
@media print {
main p {
widows: 3;
orphans: 3;
}
}
widows Example
This example demonstrates how widows and orphans can be applied to paragraphs in a printed document.
The Browser Result displays the paragraph and its formatting. To observe widow control, use print preview with enough content to cross a page boundary.
HTML Example
<div class="widows-demo">
<h3>Article Formatting Example</h3>
<p>CSS provides tools for controlling the appearance of printed documents. When paragraphs extend across page boundaries, individual lines can become separated from the rest of the paragraph.</p>
<p>The widows and orphans properties help manage these situations by specifying minimum line counts on either side of a fragmentation break. This can improve the visual consistency of longer articles and printed documentation.</p>
</div>
CSS Example
.widows-demo {
max-width: 500px;
padding: 20px;
border: 1px solid #ccc;
background-color: #f8f9fa;
}
.widows-demo h3 {
margin-top: 0;
}
.widows-demo p {
line-height: 1.6;
widows: 3;
orphans: 3;
}
@media print {
.widows-demo {
border: 0;
background-color: transparent;
}
}
Article Formatting Example
CSS provides tools for controlling the appearance of printed documents. When paragraphs extend across page boundaries, individual lines can become separated from the rest of the paragraph.
The widows and orphans properties help manage these situations by specifying minimum line counts on either side of a fragmentation break. This can improve the visual consistency of longer articles and printed documentation.
Understanding the Result
In the normal browser view, the paragraphs appear as ordinary text because no page or column fragmentation occurs.
Print Behavior
When the content crosses a page boundary during printing, the browser attempts to retain at least three lines on either side of the break.
Changing the Minimum
.widows-demo p {
widows: 4;
orphans: 2;
}
This requests at least four lines after a break and at least two lines before it.
Testing the Property
For a meaningful comparison, place several long paragraphs in a print document and inspect the resulting page breaks with different values.
Browser Differences
Printed pagination can vary between browsers, page sizes, font settings, and print configurations.
Accessibility Considerations
The widows property can improve the readability of printed text by reducing isolated lines at the beginning of pages or columns.
Maintain Paragraph Continuity
Keeping several lines together can make longer paragraphs easier to follow across page boundaries.
Avoid Excessive Constraints
Very large widow values may produce awkward page breaks or unnecessary blank space.
Support Different Page Sizes
Test printed documents using common page sizes and orientations.
Readable Typography
Widow control complements appropriate font sizes, line heights, margins, and paragraph spacing.
Semantic HTML
Use meaningful headings, paragraphs, and document structure. The property changes layout behavior but does not provide semantic information.
Screen Reader Considerations
The widows property does not change the underlying text content or reading order.
Print Accessibility
Review printed output to ensure that pagination remains clear and that text is not clipped or omitted.
Common Mistakes
Using Zero or Negative Values
p {
widows: 0;
}
The property requires a positive integer.
Using Decimal Values
p {
widows: 2.5;
}
Fractional values are invalid. Use whole numbers.
Expecting a Visible Effect on Ordinary Pages
The property generally has no visible effect in continuous scrolling layouts without fragmentation.
Confusing widows and orphans
The widows property controls lines after a break. The orphans property controls lines before a break.
Expecting an Exact Number of Lines
The specified value is a minimum, not an exact line count.
Expecting the Property to Force Page Breaks
The property influences line distribution when fragmentation occurs. It does not independently create page breaks.
Using Excessively Large Values
Large values may be impossible to satisfy and can cause awkward pagination.
Ignoring Other Fragmentation Rules
Properties such as break-before, break-after, and break-inside can affect the final layout.
Assuming Identical Browser Results
Fragmentation support and pagination algorithms vary between browsers.
Testing Only the Screen Layout
Use print preview or an appropriate fragmented layout to verify the property.
Important Considerations
Keep the following points in mind when using widows:
- The property controls the minimum number of lines after a fragmentation break.
- Its initial value is
2. - The property is inherited.
- Only positive integer values are valid.
- The specified number represents a minimum, not an exact line count.
- The property is primarily useful in printed documents and fragmented layouts.
- It can influence line distribution across page and column boundaries.
- It generally has no visible effect in ordinary continuous scrolling content.
- The
orphansproperty controls the minimum number of lines before a break. - Using
widowsandorphanstogether provides more complete paragraph control. - The property does not independently force a page or column break.
- The browser may move additional lines to satisfy the minimum.
- Fragmentation constraints may be relaxed when they cannot be satisfied.
- Short paragraphs may not contain enough lines to satisfy large values.
- Very large values can create undesirable pagination.
- Column balancing may influence fragmentation behavior.
- The
break-insideproperty can request that a block remain together. - The
break-beforeandbreak-afterproperties control additional break opportunities. - Print stylesheets are a common place to define widow and orphan control.
- Page size, font size, line height, and available width affect the resulting line count.
- The property does not alter the source text or semantic structure.
- Browser support and fragmentation behavior can vary.
- Use print preview to verify the final layout.
Browser Support
The CSS widows property has limited availability across browsers and layout contexts. Support is most relevant to paged media, while behavior in multi-column layouts can vary.
Some browsers recognize the property but do not consistently enforce its constraints in every fragmentation scenario.
For current compatibility information, visit Can I Use? and search for widows.
Standard Declaration
p {
widows: 3;
}
Print Stylesheet
@media print {
p {
widows: 3;
orphans: 3;
}
}
CSS Feature Detection
@supports (widows: 3) {
p {
widows: 3;
}
}
Feature detection checks whether the browser recognizes the declaration. It does not guarantee that widow constraints will be enforced in every fragmented layout.
Vendor Prefixes
The standard widows property does not require vendor prefixes in supporting browsers.
Testing Recommendations
Test printed pages, multi-column content, different page sizes, and paragraphs with varying line counts to confirm the browser's actual behavior.
Specifications
The widows property is defined in CSS Fragmentation Module Level 3.
CSS Fragmentation Module Level 3 - Widows and Orphans
The specification defines how minimum line counts are applied when block content is divided across fragmentation boundaries.
For additional documentation and examples, consult MDN Web Docs.
