Tillitsdone
down Scroll to discover

CSS margin-block-start A Flexible Layout Tool

CSS margin-block-start defines the logical block start margin of an element.

Use it for responsive designs with options like auto, lengths, and percentages.
thumbnail

Introduction

The margin-block-start CSS property defines the logical block start margin of an element, based on its writing mode, directionality, and text orientation. Available since September 2021, this property is widely supported across many devices and browser versions.

Browser Compatibility

The margin-block-start CSS property is well-supported across many devices and browser versions. It has been available since September 2021.

Here are the browsers that support the margin-block-start property:

  • Google Chrome 87+
  • Microsoft Edge 87+
  • Mozilla Firefox 41+
  • Opera 73+
  • Safari 12.1+

Syntax

The margin-block-start CSS property defines the logical block start margin of an element. Here’s how you can use it:

/* <length> values */
margin-block-start: 10px; /* An absolute length */
margin-block-start: 1em; /* Relative to the text size */
margin-block-start: 5%; /* Relative to the nearest block container's width */
/* Keyword values */
margin-block-start: auto;
/* Global values */
margin-block-start: inherit;
margin-block-start: initial;
margin-block-start: revert;
margin-block-start: revert-layer;
margin-block-start: unset;

Explanation

  • <length> values: You can specify the margin using absolute lengths (px, cm) or relative lengths (em, %).
    • margin-block-start: 10px; sets a fixed margin of 10 pixels.
    • margin-block-start: 1em; sets a margin relative to the text size.
    • margin-block-start: 5%; sets a margin relative to the nearest block container’s width.
  • Keyword values:
    • margin-block-start: auto; allows the browser to determine the appropriate margin.
  • Global values:
    • margin-block-start: inherit; inherits the margin from the parent element.
    • margin-block-start: initial; sets the margin to its default value.
    • margin-block-start: revert; reverts the margin to the user agent’s default stylesheet.
    • margin-block-start: revert-layer; reverts the margin to the value specified in the next lower cascade layer.
    • margin-block-start: unset; resets the margin to its natural value, which means it behaves like initial if the property is not inherited, or inherit if it is.

Values

The margin-block-start property accepts various values to control the logical block start margin of an element. These values can be specified as lengths, percentages, or keywords, offering flexibility in how you define the margin.

Here are the different types of values you can use:

  • Length values:
    • Absolute lengths: Specified in units like px, cm, or pt.
      • Example: margin-block-start: 10px;
    • Relative lengths: Specified in units like em, which are relative to the text size.
      • Example: margin-block-start: 1em;
    • Percentages: Specified as a percentage of the nearest block container’s width.
      • Example: margin-block-start: 5%;
  • Keyword values:
    • auto: Allows the browser to determine the appropriate margin based on the context.
      • Example: margin-block-start: auto;
  • Global values:
    • inherit: Inherits the margin from the parent element.
      • Example: margin-block-start: inherit;
    • initial: Sets the margin to its default value.
      • Example: margin-block-start: initial;
    • revert: Reverts the margin to the user agent’s default stylesheet.
      • Example: margin-block-start: revert;
    • revert-layer: Reverts the margin to the value specified in the next lower cascade layer.
      • Example: margin-block-start: revert-layer;
    • unset: Resets the margin to its natural value, which means it behaves like initial if the property is not inherited, or inherit if it is.
      • Example: margin-block-start: unset;

Examples

Example 1: Setting a fixed margin

HTML:

<div>
<p class="exampleText">Example text</p>
</div>

CSS:

div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
margin-block-start: 20px;
background-color: #c8c800;
}

Example 2: Using the auto keyword

HTML:

<div>
<p class="exampleText">Example text</p>
</div>

CSS:

div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
margin-block-start: auto;
background-color: #c8c800;
}

Specifications

The margin-block-start property is part of the CSS Logical Properties and Values specification, which aims to provide more intuitive and flexible ways to manage layouts in CSS. This specification helps developers create responsive designs that adapt to different writing modes, directions, and text orientations.

The margin-block-start property is defined in the following specification:

The margin-block-start property is part of a broader set of CSS logical properties that help manage layouts in a more intuitive and flexible way. These properties are designed to adapt to different writing modes, directions, and text orientations, making them invaluable for creating responsive and accessible web designs. Here are some related properties that work in conjunction with margin-block-start:

  1. margin-block-end:

  2. margin-inline-start:

  3. margin-inline-end:

  4. Margins:

  5. writing-mode:

  6. direction:

  7. text-orientation:

Using these properties, you can create flexible and user-friendly web designs. Whether it’s a simple blog or a complex app, these tools help you make visually appealing and adaptable layouts.

icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.