Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS margin-block-start Property

Posted in CSS Tutorial
Updated on Jul 29, 2024
By Mari Selvan
👁️ 11 - Views
⏳ 4 mins
💬 1 Comment
CSS margin-block-start Property

Photo Credit to CodeToFun

🙋 Introduction

The margin-block-start property in CSS is used to set the margin at the start of an element's block, depending on the writing mode, directionality, and text orientation.

This property is part of the logical properties and values, which are designed to work with different writing modes and text directions, such as left-to-right (LTR) or right-to-left (RTL).

💡 Syntax

The syntax for the margin-block-start property allows you to set a margin value in various units, such as pixels, ems, percentages, etc.

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

Here, value can be a length, percentage, or one of the global values like auto, inherit, initial, or unset.

🎛️ Default Value

The default value of the margin-block-start property is 0, meaning there is no margin applied by default at the start of the block.

🏠 Property Values

ValueDescription
lengthSpecifies the margin in fixed units like px, cm, pt, etc.
percentageSpecifies the margin as a percentage of the containing block's width.
autoThe browser calculates the margin.
inheritInherits the margin value from the parent element.
initialSets the margin to its default value.
unsetResets the margin to its natural value.

📄 Example

In this example, we set a margin of 20 pixels at the start of the block for a paragraph 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 margin-block-start Example</title>
  <style>
    p {
      margin-block-start: 20px;
    }
  </style>
</head>
<body>
  <h1>Example of margin-block-start</h1>
  <p>This paragraph has a 20px margin at the start of the block, creating space above the text.</p>
</body>
</html>

🖥️ Browser Compatibility

The margin-block-start property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. As always, testing across different browsers ensures consistent behavior.

🎉 Conclusion

The margin-block-start property is a useful tool for managing margins in a way that respects the writing mode and direction of the content.

It provides more flexibility and control over layout adjustments, especially in multilingual websites or applications. Experiment with different margin values to see how this property can enhance the spacing and layout of your web projects.

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