Tillitsdone
down Scroll to discover

CSS Margin-Bottom Mastering Space Control

Learn about CSS margin-bottom, a crucial property for controlling the space below elements.

Discover its use cases and available options, including length, percentage, and auto.
thumbnail

Introduction

The margin-bottom CSS property lets you control the space between the bottom of an element and the content below it. This is crucial for creating visually appealing and functional web designs. By tweaking this property, you can add extra space for clarity or reduce it for a more compact layout.

Description

The margin-bottom property sets the space below an element, defining the distance between the element and the content directly beneath it. This is handy for controlling the layout and spacing of web page elements, ensuring a clean and organized design.

The margin-bottom property can take various values, including lengths, percentages, and keywords like auto. Positive values increase the space, while negative values decrease it. It’s important to note that this property doesn’t affect non-replaced inline elements like <span> or <code>.

Syntax

Here’s the basic syntax for using the margin-bottom property in CSS:

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

Values

The margin-bottom property accepts various values:

  • Length: Fixed length values like pixels (px), ems (em), etc.
    margin-bottom: 20px; /* 20 pixels of space below the element */
    margin-bottom: 1em; /* Space equal to the font size of the element */
  • Percentage: Relative to the width of the containing block.
    margin-bottom: 10%; /* 10% of the width of the containing block */
  • auto: Browser automatically calculates a suitable margin value.
    margin-bottom: auto; /* Browser calculates the margin */
  • Global Values: inherit, initial, revert, revert-layer, and unset.
    margin-bottom: inherit; /* Inherits the value from the parent element */
    margin-bottom: initial; /* Sets the value to its default value */
    margin-bottom: unset; /* Resets the value to its inherited or initial value */

Formal Definition

PropertyValue
Initial Value0
Applies ToAll elements except elements with table display types other than table-caption, table, and inline-table. It also applies to ::first-letter.
InheritedNo
PercentagesRefer to the width of the containing block
Computed ValueThe percentage as specified or the absolute length
Animation TypeA length

Examples

Setting Positive and Negative Bottom Margins

HTML
<div class="container">
<div class="box0">Box 0</div>
<div class="box1">Box 1</div>
<div class="box2">Box one's negative margin pulls me up</div>
</div>
CSS
.box0 {
margin-bottom: 1em;
height: 3em;
}
.box1 {
margin-bottom: -1.5em;
height: 4em;
}
.box2 {
border: 1px dashed black;
border-width: 1px 0;
margin-bottom: 2em;
}
.container {
background-color: orange;
width: 320px;
border: 1px solid black;
}
div {
width: 320px;
background-color: gold;
}

This example shows how to use both positive and negative margins to control the spacing between elements. Positive margins add extra space, while negative margins reduce it, pulling elements closer together.

Specifications

The margin-bottom property is defined in the CSS Box Model Module Level 3 under the margin-physical section.

Browser Compatibility

The margin-bottom property is widely supported across all major browsers, including:

  • Google Chrome 1.0
  • Edge 12.0
  • Internet Explorer 3.0
  • Firefox 1.0
  • Opera 3.5
  • Safari 1.0

See Also

For further reading and related properties, you may also be interested in:

Browser Compatibility for margin-bottom

You can use the margin-bottom property confidently in your web projects. It’s supported by all major browsers, so you won’t have compatibility issues. Here’s a quick overview of browser support:

BrowserMinimum VersionRelease Date
Chrome1.0December 2008
Edge12.0July 2015
Firefox1.0November 2004
Internet Explorer3.0August 1996
Opera3.5November 1998
Safari1.0June 2003

Related CSS Properties

For more on CSS margins, check out these related properties:

  • margin-top: Sets the space above an element.
  • margin-right: Sets the space to the right of an element.
  • margin-left: Sets the space to the left of an element.
  • margin: Shorthand to set all four margins at once.

Logical Margin Properties

For more flexibility, explore these logical margin properties:

These properties help you control spacing and layout, creating dynamic and responsive web designs.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
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.