Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS orphans Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 19 - Views
⏳ 4 mins
💬 1 Comment
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.

Syntax
Copied
Copy To Clipboard
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

ValueDescription
integerA 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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy