Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS margin-inline-start Property

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

Photo Credit to CodeToFun

🙋 Introduction

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

This property is useful for creating layouts that support different writing modes, such as left-to-right (LTR) and right-to-left (RTL) languages, without needing to adjust the margin values manually for each direction.

💡 Syntax

The syntax for the margin-inline-start property is as follows:

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

Here, value can be any valid CSS length, percentage, or global value.

🎛️ Default Value

The default value of the margin-inline-start property is 0, which means no margin is applied to the start of the inline axis.

🏠 Property Values

ValueDescription
lengthA fixed value, such as px, em, rem, etc. For example, 10px or 1em.
percentageA percentage relative to the inline size of the containing block. For example, 10%.
autoThe browser calculates the margin automatically.
initialSets the property to its default value.
inheritInherits the property from its parent element.

📄 Example

In this example, we'll apply a margin at the start of the inline axis to 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-inline-start Example</title>
  <style>
    p {
      margin-inline-start: 20px;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Custom Inline Start Margin</h1>
  <p>This paragraph has a margin at the start of the inline axis.</p>
</body>
</html>

In this example, the paragraph has a margin of 20px at the start of the inline axis. If the text direction is LTR, the margin will be on the left; if the text direction is RTL, the margin will be on the right.

🖥️ Browser Compatibility

The margin-inline-start property is widely supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It provides a logical, rather than physical, way of setting margins, making it particularly useful for multilingual websites.

🎉 Conclusion

The margin-inline-start property is a powerful tool for web developers looking to create flexible and responsive layouts that support different writing modes and text directions.

By using this property, you can ensure consistent spacing and alignment across various languages and cultural settings. Experiment with different values and see how this property can enhance your website's design and usability.

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