Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS margin-block-end Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 8 - Views
⏳ 4 mins
💬 1 Comment
CSS margin-block-end Property

Photo Credit to CodeToFun

🙋 Introduction

The margin-block-end property in CSS is part of the logical properties and values module, which allows for writing CSS in a way that is more consistent across different writing modes, such as left-to-right, right-to-left, and vertical text.

This property sets the margin at the end of the block axis, which can be at the bottom or top of the element, depending on the writing mode.

💡 Syntax

The syntax for the margin-block-end property is simple. It can accept a variety of length units or keywords to define the margin size.

Syntax
Copied
Copy To Clipboard
element {
  margin-block-end: value;
}

🎛️ Default Value

The default value for margin-block-end is 0, meaning no margin is applied by default.

🏠 Property Values

ValueDescription
lengthSpecifies the margin using length units such as px, em, rem, etc. For example, 10px or 1em.
percentageSpecifies the margin as a percentage of the containing block's width. For example, 5%.
autoThe browser calculates the margin automatically.
initialSets the property to its default value.
inheritInherits the property value from its parent element.

📄 Example

In this example, we set a margin at the end of the block axis for a paragraph. Depending on the writing mode, this margin could appear at the bottom or top of the paragraph.

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 margin-block-end Example</title>
  <style>
    p {
      margin-block-end: 20px;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Margin Block End</h1>
  <p>This paragraph has a margin block end of 20px. In a left-to-right writing mode, this will appear as a margin at the bottom of the paragraph.</p>
</body>
</html>

🖥️ Browser Compatibility

The margin-block-end property is widely supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it's always advisable to test your website across different browsers and devices to ensure full compatibility.

🎉 Conclusion

The margin-block-end property is a versatile tool for web developers looking to manage margins in a logical and writing-mode-aware manner.

This property is particularly useful in internationalized websites, where text direction can vary significantly. By using logical properties like margin-block-end, you can ensure your layouts remain consistent and accessible across different writing systems.

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