CSS Properties
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.
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
Value | Description |
---|---|
length | Specifies the margin using length units such as px, em, rem, etc. For example, 10px or 1em. |
percentage | Specifies the margin as a percentage of the containing block's width. For example, 5%. |
auto | The browser calculates the margin automatically. |
initial | Sets the property to its default value. |
inherit | Inherits 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.
<!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:
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 margin-block-end Property), please comment here. I will help you immediately.