Orphan issues in CSS

css orphans handling
10 November 2024

When we talk about the design and layout adjustments of web pages, one of the specific and subtle issues that often goes unnoticed is the orphan issue in texts. An orphan refers to a scenario where a cell or a small number of cells in a new page starts or ends, while the rest of the text remains on the previous or next page. This problem can negatively impact the readability and aesthetics of the text.

In CSS, to address such issues and improve text display, we can utilize features like "widows" and "orphans". These features help in formatting the number of lines that can remain alone on a page or move to the next page, making it easier to read.

However, more precise and broader adjustments can be achieved through more advanced tools like JavaScript and CSS libraries, but for starters, a familiarity with the basic features of CSS can be very effective.

Next, we will examine a simple code example that demonstrates how to use the "widows" and "orphans" features in CSS.


p {
widows: 2;
orphans: 2;
}

The above code performs the following tasks:


p: This section specifies that the styles will apply to all HTML paragraphs.
widows: 2;: This line defines that at least 2 lines of text must remain on the new page to avoid being treated as "widows".
orphans: 2;: This specifies that at least 2 lines of text must remain at the bottom of the previous page to avoid being treated as "orphans".

FAQ

?

What is the use of the "orphans" feature in CSS?

?

Why shouldn't single words remain on a line?