Bootstrap provides us with a lot of numbers of utilities. With these classes of utilities, we can create our websites easily. But sometimes our websites are unable to catch the viewer’s attention. Sometimes we just need to add margin and padding to the website.

With this minor step, the appearance of our websites becomes more attractive and gains more attention from viewers. But sometimes it may be difficult because many users use phones, tabs, mini laptops. So our website should be responsive. But here bootstrap has spacing utility classes that are responsive-friendly with various-sized screens.

Margin:

Margin provides space around an element, outside of any defined border. So that we can add margin to an element to its every side like a top, bottom left, and right. We use margin to add a space between two elements. There are four margin properties:

  • margin-top
  • margin-bottom
  • margin-left
  • margin-right

Padding:

Padding provides space around an element, inside of any defined border. It also has four properties like

  • padding-top
  • padding-bottom
  • padding-left
  • padding-right

Notation for Margin and Padding

There are some simple notations that we can use. These notations or class names have a format. This format is {property}{sides}-{size}. It is the basic format for small devices like smartphones. But we can also add the breakpoint for different screen-sized devices.

We can also add a breakpoint. So that format is {property}{sides}-{breakpoint}-{size}.

Properties:

There are two properties. One is for margin and another one is for padding.

mfor classes that set margin
pfor classes that set padding

Sides:

As we know there are mainly four sides where we use spacing utilities. Those are

Bootstrap CodeDirections
t for classes that set margin-top or padding-top
b for classes that set margin-bottom or padding-bottom
lfor classes that set margin-left or padding-left
rfor classes that set margin-right or padding-right
Add Margin and Padding
bootstrap margin

Both sides :

We also add spacing to both sides with these notations.

xfor classes that set both *-left and *-right
yfor classes that set both *-top and *-bottom

Values:

We have some numerical values to add specific margins and padding. So We just those numerical values and bootstrap auto

ValuesCSS Values
0 0 rem
10.25 rem
20.5 rem
31 rem
41.5 rem
53 rem
Add Margin and Padding
use the mt class with different values

Break-points:

Here bootstrap has 4 breakpoints for different kinds of screens.

Breakpoints Dimensions
xm<576px
sm≥576px
md≥768px
lg≥992px
xl≥1200px
Various breakpoint in Bootstrap

If you want to learn how to create a responsive navbar with bootstrap then click here.

This Post Has One Comment

  1. zoritoler imol

    Good ?V I should definitely pronounce, impressed with your website. I had no trouble navigating through all the tabs and related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your customer to communicate. Nice task..

Leave a Reply