×

Tailwind CSS Margin

The margin class accepts a large number of values, and all of the properties are covered in the same way they are in the class form. It's a replacement for the CSS Margin Property. This class is used to generate space outside of any defined border around the element.

Different margins can be chosen for each side (top, right, bottom, left). To implement margin classes, border properties must be added. CSS padding-top, CSS padding-bottom, CSS padding-right, CSS padding-left and other CSS attributes are used for margin.

Margin Classes

The various margin classes are classified as:

  • m-0: The margin on all sides is defined by this class.
  • -m-0: The negative margin on all sides is defined by this class.
  • my-0: This class is used to establish the top and bottom margins on the y-axis.
  • -my-0: This class is used to define negative y-axis margins (margin-top and margin-bottom).
  • mx-0: This class is used to specify the x-axis margins, such as margin-left and margin-right.
  • -mx-0: This class is used to add a right-hand negative margin.
  • mt-0: This class is only used to add a top margin.
  • -mt-0: This class is used to add a negative margin to the top of the page.
  • mr-0: This class is used to add a right-hand margin.
  • -mr-0: This class is used to add a right-hand negative margin.
  • mb-0: This class is specifically used to add a bottom margin.
  • -mb-0: This class is used to add a negative margin at the bottom of the page.
  • ml-0: This class is used to add a left-hand margin.
  • -ml-0: This class is used to add a left-hand negative margin.

Note: You can replace "0" with any of the allowed "rem" values.

  1. m-0

The margin on all sides is defined by this class.

Syntax is:

<element class="m-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
        Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="m-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin
  1. -m-0

The negative margin on all sides is defined by this class.

Syntax is:

<element class="-m-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="-m-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin
  1. my-0

This class is used to establish the top and bottom margins on the y-axis.

Syntax is:

<element class="my-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="my-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin
  1. -my-0

This class is used to define negative y-axis margins (margin-top and margin-bottom).

Syntax is:

<element class="-my-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="-my-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin
  1. mx-0

This class is used to specify the x-axis margins, such as margin-left and margin-right.

Syntax is:

<element class="mx-0">...</element>

Example:

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="mx-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin
  1. -mx-0

This class is used to add a right-hand negative margin such as margin-left and margin-right.

Syntax is:

<element class="-mx-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="-mx-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin
  1. mt-0

This class is only used to add a top margin.

Syntax is:

<element class="mt-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="mt-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin

-mt-0

This class is used to add a negative margin to the top of the page.

Syntax is:

<element class="-mt-0">...</element>

Example

Code is as follows:

<!DOCTYPE html>
<head>
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
          rel="stylesheet">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Margin Class - Tailwind CSS </b>
    <div class="flex justify-center">
    <div class="m-8 bg-red-300 w-24 h-24">
        <div class="-mt-4 border-2 border-red-800
                    bg-red-600 w-16 h-16">
             
        </div>
    </div>
    </div>
</body>
</html>

Output:

Tailwind CSS Margin

Related Topics

Tailwind CSS Top / Right / Bottom / Left

In tailwind CSS, these classes take a variety of values and cover all of the characteristics in the class form. These are the CSS Top/Right/Bottom/Left properties' replacements. These classes are...

4 minutes read.

Tailwind CSS Gap

In tailwind CSS, this class accepts multiple values, and all of the properties are covered in class form. It's a replacement for the CSS gap attribute. This class is used...

4 minutes read.

Tailwind CSS Padding

This class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Padding Property. This class is used...

4 minutes read.

Tailwind CSS Place Content

This class accepts a wide range of values. It's a replacement for the CSS Place Content property. This class is used to manage how information is justified while still being...

5 minutes read.

Tailwind CSS Justify Content

In tailwind CSS, this class accepts two values. It's a replacement for CSS's justify-content attribute. This class is used to describe the flexible box container's alignment. Along the main axis...

4 minutes read.

Tailwind CSS Justify Self

The class form goes over the various properties. It's a replacement for the CSS justify-self attribute. This class is used to describe the alignment of content’s position in a CSS...

4 minutes read.

Tailwind CSS Min-Height

In tailwind CSS, this class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Min-Height Property. It...

2 minutes read.

Tailwind CSS Flex Shrink

CSS flexbox is an important element for frontend development. There are two flex-shrink options in Tailwind CSS, and all properties are covered in class form. For quick front-end development, it's...

3 minutes read.

Tailwind CSS Grid Auto Columns

The Grid Auto Columns class accepts multiple values, and all of the properties are covered in class form. It's a replacement for the CSS grid-auto-columns property. The size of the...

5 minutes read.

Tailwind CSS tutorial

Tailwind CSS can be utilized to make sites in the quickest and the least demanding way. Tailwind CSS is the most famous utility-first CSS structure on the planet for quickly...

4 minutes read.

Tailwind CSS Grid Template Columns

In tailwind CSS, this class accepts multiple values, and all of the properties are covered in class form. It's the CSS grid-template-columns property's replacement. It's used to specify the number...

2 minutes read.

Tailwind CSS Flex Direction

CSS flexbox is an important element for frontend development. CSS has four directions, therefore in tailwind CSS, all of the properties are covered in class form. It's a front-end development...

5 minutes read.

Tailwind CSS Justify Items

It is a replacement for the CSS justify-items attribute. This class is used to regulate the alignment of grid objects along their inline axis. Justify Item It is classified as: justify-items-auto justify-items-start justify-items-end justify-items-center justify-items-stretch justify-items-auto The justify-items-auto class...

4 minutes read.

Tailwind CSS Min-Width

In tailwind CSS, this class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS min-width property. This...

1 minute read.

Tailwind CSS Grid Template Rows

In tailwind CSS, this class accepts multiple values and all properties are covered in class form. It's the CSS grid-template-row property's replacement. It is used to set the number of...

2 minutes read.

Tailwind CSS Max-Height

This class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Max-Height attribute. It is used to...

3 minutes read.

Tailwind CSS Display

It acknowledges more than one worth in tailwind CSS. Every one of the properties is shrouded as in class structure. It is an option in contrast to the CSS display...

5 minutes read.

Tailwind CSS Grid Row Start / End

In tailwind CSS, this class takes several values. All of the attributes are covered in the form of a class. In CSS, it's an alternative to the grid-row attribute. It's...

4 minutes read.

Tailwind CSS Flex

CSS flexbox is an important component for frontend development. There are four flex options in Tailwind CSS, and all of the attributes are covered in class form. It's a front-end...

6 minutes read.

Tailwind CSS Box Shadow

The Tailwind CSS Box Shadow class accepts a lot of value, and all of the properties are covered in class form. We may control the box-shadow of an element by...

2 minutes read.