CSS Properties
CSS border-block Property
Photo Credit to CodeToFun
🙋 Introduction
The border-block
property in CSS is a shorthand for setting the border properties on the block-start and block-end sides of an element. In a typical English layout, the block-start side refers to the top of the element, and the block-end side refers to the bottom. However, in vertical writing modes or other languages with different writing directions, these positions can change.
This property simplifies the process of styling these borders in a way that adapts to different writing modes.
💡 Syntax
The border-block
property can be used to set the width, style, and color of the borders on both the block-start and block-end sides.
element {
border-block: <border-width> <border-style> <border-color>;
}
🎛️ Default Value
The default value for the border-block
property is:
border-block: medium none currentcolor;
This means that, by default, the borders are set to a medium width, have no border style (none), and the color is set to the current text color (currentcolor).
🏠 Property Values
Value | Description |
---|---|
border-width | The thickness of the border (e.g., thin, medium, thick, or specific measurements like 2px). |
border-style | The style of the border (e.g., solid, dotted, dashed, none). |
border-color | The color of the border (e.g., red, #ff5733, rgb(255, 87, 51)). |
You can specify one, two, or three values:
- One value: Applies the same border to both block-start and block-end.
- Two values: The first value applies to the block-start, and the second to the block-end.
📄 Example
In this example, we'll apply a solid blue border of 4px thickness to both the block-start and block-end sides of a div element.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS border-block Example</title>
<style>
div {
border-block: 4px solid blue;
}
</style>
</head>
<body>
<h1>Border-Block Example</h1>
<div>This element has a blue border on the block-start and block-end sides.</div>
</body>
</html>
🖥️ Browser Compatibility
The border-block
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is always recommended to test your website across different browsers to ensure consistent styling.
🎉 Conclusion
The border-block
property is a useful shorthand for efficiently styling the borders of elements on the block-start and block-end sides.
This property is especially handy when working with different writing modes or layouts that require adaptable designs. By mastering border-block
, you can create flexible and responsive border designs that enhance the visual appeal of your web pages.
👨💻 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 border-block Property), please comment here. I will help you immediately.