Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS break-inside Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 21 - Views
⏳ 4 mins
💬 1 Comment
CSS break-inside Property

Photo Credit to CodeToFun

🙋 Introduction

The break-inside property in CSS is used to control the behavior of breaks within elements when printing or when dealing with multi-column layouts.

This property helps to prevent unwanted breaks inside elements, ensuring that content maintains its intended structure and appearance across different devices and print formats.

💡 Syntax

The syntax for the break-inside property is straightforward. It can be applied to any element to control how breaks inside the element are handled.

Syntax
Copied
Copy To Clipboard
element {
  break-inside: value;
}

🎛️ Default Value

The default value of the break-inside property is auto, which means the browser will determine break points automatically based on its default behavior.

🏠 Property Values

ValueDescription
autoAllows, but does not force, any break inside the element.
avoidPrevents any break inside the element.
avoid-pageAvoids a page break inside the element.
avoid-columnAvoids a column break inside the element.
inheritInherits the value from its parent element.

📄 Example

In this example, we'll prevent breaks inside a column of items to ensure that the content within each column remains together.

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 break-inside Example</title>
  <style>
    .container {
      column-count: 3;
      column-gap: 20px;
    }
    .item {
      break-inside: avoid;
      margin-bottom: 20px;
      padding: 10px;
      background-color: #f0f0f0;
      border: 1px solid #ccc;
    }
  </style>
</head>
<body>
  <h1>Items with Prevented Breaks Inside Columns</h1>
  <div class="container">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
    <div class="item">Item 5</div>
    <div class="item">Item 6</div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The break-inside 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 break-inside property is a useful tool for web developers looking to control content flow in multi-column layouts and printed documents.

By preventing unwanted breaks within elements, you can maintain the integrity and readability of your content. Experiment with different values to see how this property can enhance the presentation of 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