CSS Properties
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.
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
Value | Description |
---|---|
auto | Allows, but does not force, any break inside the element. |
avoid | Prevents any break inside the element. |
avoid-page | Avoids a page break inside the element. |
avoid-column | Avoids a column break inside the element. |
inherit | Inherits 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.
<!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:
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 break-inside Property), please comment here. I will help you immediately.