VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-spacing/

⇱ Bootstrap 5 Spacing - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Spacing

Last Updated : 2 Dec, 2022

The spacing utility is used to assign responsive-friendly margin or padding values to an element or a subgroup of its sides. Padding is the area inside of any div or container, as opposed to a margin, which is the area outside of it. Margin and Padding can be added by adding Bootstrap classes in an element or container.

To change an element's appearance, Bootstrap offers a variety of responsive margin and padding utility classes. The classes are named using the format {property}{sides}-{breakpoint}-{size}  for sizes s, md, xs, lg, xl, XXL. Here sides can be t(top), b(bottom), e(end),s (start), etc.

  • Margin and padding:  Bootstrap provides several short-hand utility classes to add margin and padding between two elements or a  subgroup of an element's sides to modify its appearance. It allows spacing ranging from .25rem to 3rem.
  • Negative Margin: Bootstrap has negative margin classes that can be used to add negative margins to elements as well. These classes have a similar syntax to general spacing classes but with an n just before the size. 
  • Gap: When the display is set to grid, you can make use of gap utilities on the parent grid container. With responsive gap utilities, you don't have to add margin utilities to individual grid items. 
  • Sass: This involves the Sass map and spacing utilities that are declared in Utility API.

Example 1: Here is an example of margin and padding using bootstrap spacing classes.

Output:

👁 Image
Padding in Margin in Bootstrap 5

Example 2: Here is an example of a gap using bootstrap spacing classes.

Output:

👁 Image
Gap utility in Bootstrap 5

Reference: https://getbootstrap.com/docs/5.0/utilities/spacing/ 

Comment

Explore