CSS Properties
CSS orphans Property
Photo Credit to CodeToFun
🙋 Introduction
The orphans
property in CSS is used to control the minimum number of lines in a block container that must be left at the bottom of a page or column.
This property is especially useful for improving the readability of text by preventing the situation where only a few lines of text appear alone at the bottom of a page or column.
💡 Syntax
The syntax for the orphans
property is simple and allows you to specify an integer value.
element {
orphans: number;
}
Here, number represents the minimum number of lines that should be left at the bottom of a page or column.
🎛️ Default Value
The default value of the orphans
property is 2. This means that if the property is not explicitly set, at least two lines will be left at the bottom of a page or column.
🏠 Property Values
Value | Description |
---|---|
integer | A positive integer that specifies the minimum number of lines that must be left at the bottom of a page or column. For example, orphans: 3; ensures that at least three lines will remain at the bottom. |
📄 Example
In this example, we will set the orphans
property to ensure that at least three lines of text are left at the bottom of a column.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS orphans Property Example</title>
<style>
.example {
orphans: 3;
width: 300px;
height: 200px;
overflow: hidden;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<h1>Text with Orphans Property</h1>
<div class="example">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel libero vehicula,
venenatis nisl et, congue dui. Aenean a nisi sit amet dolor sodales scelerisque. Nulla
facilisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas. Vivamus dictum venenatis odio a tincidunt.
</div>
</body>
</html>
🖥️ Browser Compatibility
The orphans
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, and Edge. It may not be supported in all versions of Internet Explorer. Testing across different browsers is recommended to ensure consistent behavior.
🎉 Conclusion
The orphans
property is a useful tool for managing the layout of text within block containers, ensuring a more polished and readable presentation.
By specifying the minimum number of lines that should be left at the bottom of a page or column, you can improve the overall aesthetics and usability of your content. Experiment with different values to find the best fit for your design needs.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS orphans Property), please comment here. I will help you immediately.