Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS windows Property

Posted in CSS Tutorial
Updated on Nov 19, 2024
By Mari Selvan
👁️ 23 - Views
⏳ 4 mins
💬 1 Comment
CSS windows Property

Photo Credit to CodeToFun

🙋 Introduction

The widows property in CSS is used to control the minimum number of lines of a block container that must be shown at the top of a page or column.

This property helps in preventing single lines (widows) from appearing at the top of a new page or column, which can improve the readability and visual flow of the text.

💡 Syntax

The syntax for the widows property is simple. It can be applied to any block container element.

Syntax
Copied
Copy To Clipboard
element {
  widows: value;
}

Here, value is a positive integer specifying the minimum number of lines.

🎛️ Default Value

The default value of the widows property is 2. This means that by default, at least two lines of a block container must be shown at the top of a page or column.

🏠 Property Values

ValueDescription
integerA positive integer specifying the minimum number of lines that must be shown.

📄 Example

In this example, we'll ensure that at least three lines of a paragraph are shown at the top of a new page or 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 widows Property Example</title>
  <style>
    p {
      widows: 3;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Custom Widows Property</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa.</p>
</body>
</html>

🖥️ Browser Compatibility

The widows property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The widows property is a useful tool for web developers looking to improve the readability and visual flow of text on their web pages.

By ensuring that a minimum number of lines are shown at the top of a page or column, you can avoid awkward breaks and enhance the overall user experience. Experiment with different values to see how this property can benefit your web projects.

👨‍💻 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