CSS margin-inline property
The margin-inline CSS property is your key to controlling the space around elements on the horizontal axis (left and right). Think of it like carefully arranging furniture in a room for that perfect mix of comfort and style.
What does it do?
The margin-inline property sets the amount of space on the left and right sides of these website elements:
- Text blocks (paragraphs, headings, etc.)
- Images
- Buttons
- Videos
- And other content boxes
Why does it matter?
margin-inline brings these benefits to your website:
- Readability: Adds breathing room between elements making your content easier to read and digest.
- Aesthetics: Creates a visually pleasing layout and prevents elements from looking cramped.
- User Experience: Enhances how users interact with your site.
How to use it
You can set margin-inline with various values:
- Pixels (px): For example, margin-inline: 30px;
- Percentages (%): Offers flexibility based on the container size.
- auto: Lets the browser calculate the best margin for you.
Example:
img { /* Targets all image elements */
  margin-inline: 15px;  /* Adds 15 pixels of space on both left and right */
}
- Logical Properties: margin-inlineis based on the writing mode of the language. In left-to-right languages, it controls side margins, while it affects top/bottom in vertical languages.
- Shorthand Power: margin-inlinesets both left and right. For individual sides, usemargin-leftandmargin-right.
- Relationship to Other Margin Properties: margin-inlineis part of the larger ‘margin’ family, includingmargin-top,margin-bottom, and the generalmarginproperty.