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