CSS Properties
CSS margin-inline-end Property
Photo Credit to CodeToFun
🙋 Introduction
The margin-inline-end
property in CSS is part of the Logical Properties and Values module.
This property sets the margin space on the end side of an element, based on the writing mode, directionality, and text orientation of the document.
Unlike physical properties like margin-right, margin-inline-end
adapts to the writing mode, making it more versatile for internationalization and responsive design.
💡 Syntax
The syntax for the margin-inline-end
property is straightforward. It accepts any valid CSS length, percentage, or the keywords auto or inherit.
element {
margin-inline-end: value;
}
- value: Can be a length (e.g., px, em, rem), percentage, or keywords like auto or inherit.
🎛️ Default Value
The default value of the margin-inline-end
property is 0, meaning no margin is applied by default.
🏠 Property Values
Value | Description |
---|---|
length | Specifies a fixed margin size. For example, 20px, 1em. |
percentage | Sets the margin as a percentage of the containing block's inline size. |
auto | The browser calculates the margin. |
inherit | Inherits the margin value from the parent element. |
📄 Example
In this example, we'll apply a margin of 20px to the inline end side of a <div> element.
<!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-end Example</title>
<style>
.box {
margin-inline-end: 20px;
border: 1px solid #000;
padding: 10px;
}
</style>
</head>
<body>
<h1>Example of margin-inline-end</h1>
<div class="box">
This box has a margin-inline-end of 20px.
</div>
</body>
</html>
🖥️ Browser Compatibility
The margin-inline-end
property is widely supported in modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. However, always ensure to test your website across different browsers to maintain consistent styling.
🎉 Conclusion
The margin-inline-end
property is a valuable addition for developers looking to create responsive and adaptable layouts, especially for websites that need to support different languages and writing modes.
By using logical properties like margin-inline-end
, you can simplify your CSS and make your designs more flexible. Experiment with different values and see how this property can enhance your layouts.
👨💻 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-inline-end Property), please comment here. I will help you immediately.