Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS border-block Property

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

Syntax
Copied
Copy To Clipboard
element {
  border-block: <border-width> <border-style> <border-color>;
}

🎛️ Default Value

The default value for the border-block property is:

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

ValueDescription
border-widthThe thickness of the border (e.g., thin, medium, thick, or specific measurements like 2px).
border-styleThe style of the border (e.g., solid, dotted, dashed, none).
border-colorThe 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.

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 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:

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