Skip to content
Related Articles
Open in App
Not now

Related Articles

BootStrap 5 Utilities Margin and Padding

Improve Article
Save Article
  • Last Updated : 06 Feb, 2023
Improve Article
Save Article

In Bootstrap 5, the margin and padding utilities are used to add space around elements. The margin utilities are used to add space outside of an element, while the padding utilities are used to add space inside of an element.

Bootstrap 5 Utilities Margin and padding Classes: There are no different classes for these utilities, you can use the margin and padding spacing utilities to assign the space around the elements.

Syntax:

<tag class="m-{size}-{direction}">...</tag>

Note: Classes described for ‘m for margin,p for padding,{size}‘: The size of the margin or padding, where size can be 0, 1, 2, 3, 4, 5 and {direction}: The direction of the margin or padding, where direction can be t, b, l, r, x, y.

Example 1: In this example, we will demonstrate bootstrap 5 margins.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <link href=
          rel="stylesheet"
          integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
          crossorigin="anonymous">
</head>
 
<body>
    <div class="container bg-danger">
        <h1 class="text-success mt-5 m-auto">GeeksforGeeks</h1>
        <h2 class="mt-5"> BootStrap5 Utilities Margin and padding</h2>
        <h1 class="text-success mt-5 m-auto">GeeksforGeeks</h1>
    </div>
</body>
 
</html>

Output:

BootStarp 5 Utilities Margin and Padding

Bootstrap 5 Utilities Margin and Padding

Example 2: In this example, we will demonstrate bootstrap 5 paddings.

HTML




<!DOCTYPE html>
<html>
<head>
    <link href=
          rel="stylesheet"
          integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
          crossorigin="anonymous">
</head>
<body>
    <div class="container">
        <h1 class="text-success mt-5 m-auto">
            GeeksforGeeks
        </h1>
        <div class="pt-0 bg-primary">Padding Top none </div>
        <div class="pt-1 bg-danger">Padding Top 1</div>
        <div class="pt-2 bg-sucsess">Padding Top 2</div>
        <div class="pt-3 bg-info">Padding Top 3</div>
    </div>
</body>
</html>

Output:

BootStarp 5 Utilities Margin and Padding

BootStrap 5 Utilities Margin and Padding

Reference: https://getbootstrap.com/docs/5.0/layout/utilities/#margin-and-padding


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!