Open In App
Related Articles

CSS margin-bottom Property

Improve Article
Improve
Save Article
Save
Like Article
Like

The CSS margin-bottom property is used to specify the amount of margin to be used on the bottom of an element. The margin can be set in terms of length or percentage. 

Syntax:

margin-bottom: <length> | <percentage> | auto

Property values:

  • Length: This value specifies the length of margin with a fixed value. This value can be positive, negative or zero. 

Example: 

html




<!DOCTYPE html>
<html>
<head>
    <title>CSS margin-bottom</title>
    <style>
        div{
            background-color: lightgreen;
        }
    </style>
</head>
<body>
    <h1 style="color: green">GeeksforGeeks</h1>
     
    <!-- margin-bottom for below div
        is set to 50px -->
    <div style="margin-bottom: 50px">Line One</div>
     
    <!-- margin-bottom for below div
        is set to 0px -->
    <div style="margin-bottom: 0px">Line Two</div>
     
    <div>Line Three</div>
</body>
</html>                   


Output:

 

  • Percentage: This value specifies the amount of margin as a percentage relative to the width of the containing element. 

Example: 

html




<!DOCTYPE html>
<html>
<head>
    <title>CSS margin-bottom</title>
    <style>
        h1 {
            color: green;
        }
         
        .larger {
            width: 300px;
            background-color: white;
        }
         
        .smaller {
            width: 100px;
            background-color: white;
        }
         
        div{
            background-color: lightgreen;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
     
    <!-- margin-bottom is set to 10% with width of
        containing box set to 300px -->
    <div class="larger">
        <div style="margin-bottom: 10%";>Line One</div>
        <div>Line Two</div>
    </div>
     
    <!-- margin-bottom is set to 10% with width of
        containing box set to 100px -->
    <div class="smaller">
        <div style="margin-bottom: 10%;">Line One</div>
        <div>Line Two</div>
    </div>
</body>
</html>                   


Output:

 

  • auto: If the value of this property is set as “auto” then the browser automatically calculates a suitable value for the margin size.

Supported Browsers: The browser supported by margin-bottom property are listed below:

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 3
  • Firefox 1
  • Opera 3.5
  • Safari 1

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 Jun, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials