totn CSS

CSS: margin-bottom property

This CSS tutorial explains how to use the CSS property called margin-bottom with syntax and examples.

Description

The CSS margin-bottom property defines the margin on the bottom of an element.

Syntax

The syntax for the margin-bottom CSS property is:

margin-bottom: value;

Parameters or Arguments

value

The margin to apply to the bottom of the element. It can be one of the following:

Value Description
fixed Fixed value expressed in px, em, ...
div { margin-bottom: 5px; }
div { margin-bottom: 4em; }
percentage Percentage value
div { margin-bottom: 8%; }
auto Used for centering blocks
div { margin-bottom: auto; }
inherit Element will inherit the margin-bottom from its parent element
div { margin-bottom: inherit; }

Note

  • The value in the CSS margin-bottom property can be expressed as either a fixed value or as a percentage.
  • Negative values are allowed in the CSS margin-bottom property.
  • When the value is provided as a percentage, it is relative to the width of the containing block.
  • See also margin, margin-top, margin-left, and margin-right.

Browser Compatibility

The CSS margin-bottom property has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • IE Phone
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the margin-bottom property below, exploring examples of how to use this property in CSS with a fixed value as well as a percentage value.

Using Fixed Value

Let's look at a CSS margin-bottom example where we have provided the value as a fixed value.

div { margin-bottom: 5px; }

In this example, we have provided a value of 5px which would apply to the bottom of the element.

You can also express fixed values in em's when using the margin-bottom property.

For example:

div { margin-bottom: 2em; }

In this margin-bottom example, we have provided a value of 2em which would apply to the bottom of the element.

Using Percentage

Let's look at a CSS margin-bottom example where we have provided the value as a percentage.

div { margin-bottom: 2%; }

In this CSS margin-bottom example, we have provided a value of 2% which would apply to the bottom of the element.

Using Auto

Let's look at an example where we have provided the value as auto.

div { margin-bottom: auto; }

In this example, we have set the bottom margin to auto for the <div> tag. The auto value is generally used to center blocks.