Bootstrap has many facility of classes to easily style elements in HTML. It include a various responsive padding and margin classes for modification of the appearance of element. Spacing utilities have no breakpoints symbols to apply to the breakpoints.
Following Syntax are used in the Various Classes for adding spacing:
- (property)(sides)-(size) for xs
- (property)(sides)-(breakpoint)-(size) for sm, md, lg, and xl.
Property : There are two ways of adding spacing to the elements.
- m: This property defines the margin. Margin provide with an edge or border.
- p: This property defines the padding. Padding properties are used to generate space around a content.
Sides : This allows user to add spacing in content to a specific side wherever required.
- t : margin-top/padding-top.
- b : margin-bottom/padding-bottom.
- l : margin-left/padding-left.
- r : margin-right/padding-right.
- x : for padding-left and padding-right/margin-left and margin-right.
- y : for padding-top and padding-bottom/margin-top and margin-bottom.
- blank : margin/padding on all sides of the element.
Size: This allows user to add a specific amount of spacing to a level.
- 0 – 0px margin/padding.
- 1 – 4px margin/padding.
- 2 – 8px margin/padding.
- 3 – 16px margin/padding.
- 4 – 24px margin/padding.
- 5 – 48px margin/padding.
- auto – auto margin.
Breakpoint: Breakpoints are points where the website content can adjust according to the device and allow to show the best layout to the user.
- sm, md, lg and xl are following breakpoints.
- For breakpoint – xs:
- For breakpoint – md:
- For breakpoint – lg:
- For breakpoint – xl:
Responsive Spacing Table:
|Appears on all||.ml-3|
|Appears only on xs||.ml-3 .ml-sm-0|
|Appears only on sm||.ml-sm-3 .ml-md-0|
|Appears only on md||.ml-md-3 .ml-lg-0|
|Appears only on lg||.ml-lg-3 .d-xl-0|
|Appears only on xl||.ml-xl-3|
- CSS border-spacing Property
- CSS | letter-spacing Property
- CSS | word-spacing Property
- Popovers in bootstrap with examples
- Containers in Bootstrap with examples
- Bootstrap Buttons with Examples
- Borders in bootstrap with examples
- BootStrap | Positioning an element with Examples
- Visibility of elements in bootstrap with Examples
- Flexbox utilities in bootstrap with examples
- Vertical alignment in Bootstrap with Examples
- Input Groups in Bootstrap with Examples
- Display Property in Bootstrap with Examples
- Colors and gradients in bootstrap with examples
- Bootstrap | Float utilities with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.