×

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 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 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 Grow

CSS flexbox is an important element for frontend development; there are two flex-grow options in Tailwind CSS, and all attributes are covered in class form. It is an alternative to...

3 minutes read.

Tailwind CSS Place Self

The tailwind CSS Place self class accepts a wide range of values. It's a replacement for the CSS Place Items property. This class is used to manage how a single...

4 minutes read.

Tailwind CSS Float

The float class acknowledges more than one worth (value) in tailwind CSS. It is an option in contrast to the CSS float property. The float class characterizes the progression of...

4 minutes read.

Tailwind CSS Align Self

This class accepts a wide range of values. It's a replacement for the CSS Align Self attribute. This class is used to control how a flex or grid item is...

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 Fill

The CSS Fill class accepts a lot of value, and all of the properties are covered in class form. It is a presentation attribute that controls how an SVG shape's...

1 minute 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 Grid Column Start / End

This class accepts multiple values, and all of the properties are covered in class form. It was used as a replacement to the CSS grid-column property in CSS to express...

3 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 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 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 Align Content

In Tailwind CSS, this class accepts a wide range of values. It's a replacement for the CSS Align Content feature. This class is used to modify the flex-wrap property's behavior....

5 minutes read.

Tailwind CSS Box Sizing

Tailwind CSS Box sizing class acknowledges more than one worth in tailwind CSS. Each property is shrouded as a class structure. It is an option in contrast to the CSS...

2 minutes read.

Tailwind CSS Clear

This class acknowledges more than one worth in tailwind CSS. Every one of the properties is canvassed as in class form. It is an option in contrast to the CSS...

5 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 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 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 Object Position

It acknowledges more than one value in tailwind CSS. Every one of the properties is covered as in class form. It is the option in contrast to the CSS object-position...

2 minutes read.