
Spacing
Assign or to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties. All classes are multiples on the global default value, (10px).
The classes are named using the format:
Where property is one of:
- - for classes that set
- - for classes that set
Where sides is one of:
- - for classes that set or
- - for classes that set or
- - for classes that set or
- - for classes that set or
- - for classes that set both and
- - for classes that set both and
- - for classes that set a or on all 4 sides of the element
Where size is one of:
- - for classes that eliminate the or by setting it to
- - (by default) for classes that set the or to or
- - (by default) for classes that set the or to or
- - (by default) for classes that set the or to or
(You can add more sizes by adding entries to the Sass map variable.)
Here are some representative examples of these classes:
Horizontal centering
Additionally, Bootstrap also includes an class for horizontally centering fixed-width block level content by setting the horizontal margins to .
Spacing in Bootstrap with Examples
Bootstrap has many facility of classes to easily style elements in HTML. It includes 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 provides an edge or border.
- p: This property defines the padding. Padding properties are used to generate space around the content.
Sides: This allows users 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 users 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 the following breakpoints.
Syntax:
- For breakpoint – xs:
- For breakpoint – md:
- For breakpoint – lg:
- For breakpoint – xl:
Responsive Spacing Table:
Screen Size | Class |
---|---|
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 |
Example 1:
HTML
Output:
Example 2:
HTML
Output:
Example 3:
HTML
Output:
Supported Browser:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Bootstrap spacing
Getting started: download & setup
Download
All of the components and features are a part of the MDBootstrap package.
MDBootstrap (Material Design for Bootstrap) is an MIT Licensed framework - free for personal & commercial use.
It combines the esthetic of Material Design and the functionalities of the newest Bootstrap.
Click on the button below to visit the Getting Started Page, where you can download the latest MDBootstrap package.
MDBootstrap DownloadMDBootstrap AboutMDB Pro
Using components and features labeled as MDB Pro component requires the MDB Pro package - a powerful UI Kit containing over 10,000 components, dozens of plugins and much more cool features.
Click the button below to learn more about the MDBootstrap Pro package.
MDBootstrap ProTutorials
If you need any additional help, use our "5 min Quick Start" guide or start full Bootstrap tutorial.
5 min Quick StartFull Bootstrap TutorialCompilation & Customization
To reduce the weight of MDBootstrap package even more, you can compile your own, custom package containing only those components and features that you need.
If you need additional help with compiling your custom package, please use our Compilation & Customization tutorial.
Compilation & Customization tutorialMap of dependencies of SCSS files in MDBootstrap:
Map of dependencies of JavaScript modules in MDBootstrap:
Integrations with Angular, React or Vue
Apart from the standard Bootstrap integration (using jQuery), MDBootstrap also integrates with Angular, React and Vue.
About MDB AngularAbout MDB ReactAbout MDB VueExclusive resources
MDBootstrap is a platform for web creators and MDB packages are only a part of it.
If you sign up you'll gain free access to other useful tools & resources including:
- Community developed components & design projects
- Technical support & community forum
- CLI interface & free project hosting
- Helpful articles & news agregators
...and much more!
Don't hesitate and sign up now!
Sign up nowSpacing
Assign responsive-friendly or values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties. Classes are built from a default Sass map ranging from to .
Contents
Notation
Spacing utilities that apply to all breakpoints, from to , have no breakpoint abbreviation in them. This is because those classes are applied from and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
The classes are named using the format for and for , , , and .
Where property is one of:
- - for classes that set
- - for classes that set
Where sides is one of:
- - for classes that set or
- - for classes that set or
- - for classes that set or
- - for classes that set or
- - for classes that set both and
- - for classes that set both and
- blank - for classes that set a or on all 4 sides of the element
Where size is one of:
- - for classes that eliminate the or by setting it to
- - (by default) for classes that set the or to or
- - (by default) for classes that set the or to or
- - (by default) for classes that set the or to or
- - (by default) for classes that set the or to or
- - (by default) for classes that set the or to or
(You can add more sizes by adding entries to the Sass map variable.)
Examples
Here are some representative examples of these classes:
Horizontal centering
Additionally, Bootstrap also includes an class for horizontally centering fixed-width block level content—that is, content that has and a set—by setting the horizontal margins to .
Spacing bootstrap 4
Bootstrap 4 Utilities
❮ PreviousNext ❯
Bootstrap 4 Utilities
Bootstrap 4 has a lot of utility/helper classes to quickly style elements without using any CSS code.
Borders
Use the classes to add or remove borders from an element:
Example
Example
<span class="border"></span>
<span class="border border-0"></span>
<span class="border border-top-0"></span>
<span class="border border-right-0"></span>
<span class="border border-bottom-0"></span>
<span class="border border-left-0"></span>
Border Color
Add a color to the border with any of the contextual border color classes:
Example
Example
<span class="border border-primary"></span>
<span class="border border-secondary"></span>
<span class="border border-success"></span>
<span class="border border-danger"></span>
<span class="border border-warning"></span>
<span class="border border-info"></span>
<span class="border border-light"></span>
<span class="border border-dark"></span>
<span class="border border-white"></span>
Border Radius
Add rounded corners to an element with the classes:
Example
Example
<span class="rounded-sm"></span>
<span class="rounded"></span>
<span class="rounded-lg"></span>
<span class="rounded-top"></span>
<span class="rounded-right"></span>
<span class="rounded-bottom"></span>
<span class="rounded-left"></span>
<span class="rounded-circle"></span>
<span class="rounded-0"></span>
Float and Clearfix
Float an element to the right with the class or to the left with , and clear floats with the class:
Example
Example
<div class="clearfix">
<span class="float-left">Float left</span>
<span class="float-right">Float right</span>
</div>
Responsive Floats
Float an element to the left or to the right depending on screen width, with the responsive float classes ( - where * is (>=576px), (>=768px), (>=992px) or (>=1200px)):
Example
Float right on small screens or wider
Float right on medium screens or wider
Float right on large screens or wider
Float right on extra large screens or wider
Float none
Example
<div class="float-sm-right">Float right on small screens or wider</div><br>
<div class="float-md-right">Float right on medium screens or wider</div><br>
<div class="float-lg-right">Float right on large screens or wider</div><br>
<div class="float-xl-right">Float right on extra large screens or wider</div><br>
<div class="float-none">Float none</div>
Center Align
Center an element with the class (adds margin-left and margin-right: auto):
Example
Example
<div class="mx-auto bg-warning" style="width:150px">Centered</div>
Width
Set the width of an element with the w-* classes (, , , , ):
Example
Width 25%
Width 50%
Width 75%
Width 100%
Max Width 100%
Example
<div class="w-25 bg-warning">Width 25%</div>
<div class="w-50 bg-warning">Width 50%</div>
<div class="w-75 bg-warning">Width 75%</div>
<div class="w-100 bg-warning">Width 100%</div>
<div class="mw-100 bg-warning">Max Width 100%</div>
Height
Set the height of an element with the h-* classes (, , , , ):
Example
Height 25%
Height 50%
Height 75%
Height 100%
Max Height 100%
Example
<div style="height:200px;background-color:#ddd">
<div class="h-25 bg-warning">Height 25%</div>
<div class="h-50 bg-warning">Height 50%</div>
<div class="h-75 bg-warning">Height 75%</div>
<div class="h-100 bg-warning">Height 100%</div>
<div class="mh-100 bg-warning" style="height:500px">Max Height 100%</div>
</div>
Spacing
Bootstrap 4 has a wide range of responsive margin and padding utility classes. They work for all breakpoints: (<=576px), (>=576px), (>=768px), (>=992px) or (>=1200px)):
The classes are used in the format: for and for , , , and .
Where property is one of:
- - sets
- - sets
Where sides is one of:
- - sets or
- - sets or
- - sets or
- - sets or
- - sets both and or and
- - sets both and or and
- blank - sets a or on all 4 sides of the element
Where size is one of:
- - sets or to
- - sets or to (4px if font-size is 16px)
- - sets or to (8px if font-size is 16px)
- - sets or to (16px if font-size is 16px)
- - sets or to (24px if font-size is 16px)
- - sets or to (48px if font-size is 16px)
- - sets to auto
Note: margins can also be negative, by adding an "n" in front of size:
- - sets to (-4px if font-size is 16px)
- - sets to (-8px if font-size is 16px)
- - sets to (-16px if font-size is 16px)
- - sets to (-24px if font-size is 16px)
- - sets to (-48px if font-size is 16px)
Example
I only have a top padding (1.5rem = 24px)
I have a padding on all sides (3rem = 48px)
I have a margin on all sides (3rem = 48px) and a bottom padding (3rem = 48px)
Example
<div class="pt-4 bg-warning">I only have a top padding (1.5rem = 24px)</div>
<div class="p-5 bg-success">I have a padding on all sides (3rem = 48px)</div>
<div class="m-5 pb-5 bg-info">I have a margin on all sides (3rem = 48px) and a bottom padding (3rem = 48px)</div>
More Spacing Examples
margin on all sides | Try it |
margin top | Try it |
margin bottom | Try it |
margin left | Try it |
margin right | Try it |
margin left and right | Try it |
margin top and bottom | Try it |
padding on all sides | Try it |
padding top | Try it |
padding bottom | Try it |
padding left | Try it |
padding right | Try it |
padding top and bottom | Try it |
padding left and right | Try it |
Shadows
Use the classes to add shadows to an element:
Example
No shadow
Small shadow
Default shadow
Large shadow
Example
<div class="shadow-none p-4 mb-4 bg-light">No shadow</div>
<div class="shadow-sm p-4 mb-4 bg-white">Small shadow</div>
<div class="shadow p-4 mb-4 bg-white">Default shadow</div>
<div class="shadow-lg p-4 mb-4 bg-white">Large shadow</div>
Vertical Align
Use the classes to change the alignment of elements (only works on inline, inline-block, inline-table and table cell elements):
Example
baselinetopmiddlebottomtext-toptext-bottom
Example
<span class="align-baseline">baseline</span>
<span class="align-top">top</span>
<span class="align-middle">middle</span>
<span class="align-bottom">bottom</span>
<span class="align-text-top">text-top</span>
<span class="align-text-bottom">text-bottom</span>
Responsive Embeds
Create responsive video or slideshow embeds based on the width of the parent.
Add the to any embed elements (like <iframe> or <video>) in a parent element with and an aspect ratio of your choice:
Example
Example
<!-- 21:9 aspect ratio -->
<div class="embed-responsive embed-responsive-21by9">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
<!-- 4:3 aspect ratio -->
<div class="embed-responsive embed-responsive-4by3">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
<!-- 1:1 aspect ratio -->
<div class="embed-responsive embed-responsive-1by1">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
Visibility
Use the or classes to control the visibility of elements. Note: These classes do not change the CSS display value. They only add or :
Example
I am visible
I am invisible
Example
<div class="visible">I am visible</div>
<div class="invisible">I am invisible</div>
Position
Use the class to make any element fixed/stay at the top of the page:
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
...
</nav>
Use the class to make any element fixed/stay at the bottom of the page:
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-bottom">
...
</nav>
Use the class to make any element fixed/stay at the top of the page when you scroll past it. Note: This class does not work in IE11 and earlier (will treat it as ).
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
...
</nav>
Close icon
Use the class to style a close icon. This is often used for alerts and modals. Note that we use the symbol to create the actual icon (a better looking "x"). Also note that it floats right by default:
Example
Example
<button type="button" class="close">×</button>
Screenreaders
Use the class to hide an element on all devices, except screen readers:
Example
<span class="sr-only">I will be hidden on all screens except for screen readers.</span>
Try it Yourself »Colors
As described in the Colors chapter, here is a list of all text and background color classes:
The classes for text colors are: , , , , , , , , , (default body color/often black) and :
Example
This text is muted.
This text is important.
This text indicates success.
This text represents some information.
This text represents a warning.
This text represents danger.
Secondary text.
Dark grey text.
Body text.
Light grey text.
Contextual text classes can also be used on links, which will add a darker hover color:
You can also add 50% opacity for black or white text with the or classes:
Example
Black text with 50% opacity on white background
White text with 50% opacity on black background
Background Colors
The classes for background colors are: , , , , , , and .
Note that background colors do not set the text color, so in some cases you'll want to use them together with a class.
Example
This text is important.
This text indicates success.
This text represents some information.
This text represents a warning.
This text represents danger.
Secondary background color.
Dark grey background color.
Light grey background color.
Typography/Text Classes
As described in the Typography chapter, here is a list of all typography/text classes:
Class | Description | Example |
---|---|---|
Display headings are used to stand out more than normal headings (larger font-size and lighter font-weight), and there are four classes to choose from: , , , | Try it | |
Bold text | Try it | |
Bolder bold text | Try it | |
Normal text | Try it | |
Light weight text | Try it | |
Lighter weight text | Try it | |
Italic text | Try it | |
Makes a paragraph stand out | Try it | |
Indicates smaller text (set to 85% of the size of the parent) | Try it | |
Prevents long text from breaking layout | Try it | |
Indicates center-aligned text | Try it | |
Removes the underline from a link | Try it | |
Indicates left-aligned text | Try it | |
Indicates justified text | Try it | |
Monospaced text | Try it | |
Indicates no wrap text | Try it | |
Indicates lowercased text | Try it | |
Resets the color of a text or a link (inherits the color from its parent) | Try it | |
Indicates right-aligned text | Try it | |
Indicates uppercased text | Try it | |
Indicates capitalized text | Try it | |
Displays the text inside an element in a slightly smaller font size | Try it | |
Removes the default list-style and left margin on list items (works on both and ). This class only applies to immediate children list items (to remove the default list-style from any nested lists, apply this class to any nested lists as well) | Try it | |
Places all list items on a single line (used together with on each <li> elements) | Try it | |
Makes a element scrollable | Try it |
Block Elements
To make an element into a block element, add the class. Use any of the classes to control WHEN the element should be a block element on a specific screen width:
Example
d-blockd-sm-blockd-md-blockd-lg-blockd-xl-block
Example
<span class="d-block bg-success">d-block</span>
<span class="d-sm-block bg-success">d-sm-block</span>
<span class="d-md-block bg-success">d-md-block</span>
<span class="d-lg-block bg-success">d-lg-block</span>
<span class="d-xl-block bg-success">d-xl-block</span>
Other Display Classes
Other display classes are also available:
Class | Description | Example |
---|---|---|
Hides an element | Try it | |
Hides an element on a specific screen size | Try it | |
Makes an element inline | Try it | |
Makes an element inline on a specific screen size | Try it | |
Makes an element inline block | Try it | |
Makes an element inline block on a specific screen size | Try it | |
Makes an element display as a table | Try it | |
Makes an element display as a table on a specific screen size | Try it | |
Makes an element display as a table cell | Try it | |
Makes an element display as a table cell on a specific screen size | Try it | |
Makes an element display as a table row | Try it | |
Makes an element display as a table row on a specific screen size | Try it | |
Creates a flexbox container and transforms direct children into flex items | Try it | |
Creates a flexbox container on a specific screen size | Try it | |
Creates an inline flexbox container | Try it | |
Creates an inline flexbox container on a specific screen size | Try it |
Flex
Use classes to control the layout with flexbox.
Read more about Bootstrap 4 Flex, in our next chapter.
Example
Horizontal:
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Vertical:
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
❮ PreviousNext ❯
The margin property adds spacing between the elements while CSS padding between the content and container boundary.
The Bootstrap 4 has built-in utility responsive classes for margin and padding that you may use easily in various elements to manage the spacing.
A few quick examples
Syntax of using shorthand margin and padding
You may use the padding and margin shorthand Bootstrap 4 classes as follows:
For extra small devices i.e. xs:
{property}{sides}-{size}
For other devices/viewports (small, medium, large and extra large):
{property}{sides}-{breakpoint}-{size}
Where:
property = m for margin and p for padding
Following are sides shorthand meanings:
- l = defines the left-margin or left-padding
- r = defines the right-margin or right-padding
- t = defines the top-margin or top-padding
- b = defines the bottom-margin or right-padding
- x = For setting left and right padding and margins by the single call
- y = For setting top and bottom margins
- blank = margin and padding for all sides
The size can be from value 0 to 5 and auto. I will show you examples for seeing the difference.
The breakpoint = sm, md, lg, and xl.
Combining all the above, the left padding complete code can be (for example):
For left padding in extra small devices:
pl-2
or for medium to extra large:
pl-md-2
Now, let me show you the usage of these padding and margin shorthand utility classes in action in Bootstrap 4.
The example of Bootstrap padding classes for all directions
In this example, the padding classes are used in paragraphs as follows:
As such no breakpoint is used, so this applies to viewports from extra small to extra large. That means, if you resize the example page, the padding maintains for all viewports. Have a look:
See online demo and code
The markup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <div class="container">
<h3 class="p-3 text-primary">The demo of padding classes</h3>
<p class="p-5 bg-info text-warning">p-5</p>
<p class="p-4 bg-success text-warning">p-4</p>
<p class="p-3 bg-primary text-warning">p-3</p>
<p class="p-2 bg-secondary text-warning">p-2</p>
<p class="p-1 bg-danger text-white">p-1</p>
<p class="p-0 bg-primary text-warning">p-0</p>
</div> |
You can see, the p-0is adjacent to the container div element and the difference of padding in all directions for different utility classes.
Using the left and top padding classes example
In the following example, four paragraphs are given different individual padding classes. The first applies from the small devices by using pl-sm-5 class. That is, only the left padding will apply.
In the second <p> tag, the pt-md-2 and pl-md-3 classes are used. That means from medium viewports, the top padding will be two points and left padding is 3.
For the third paragraph, pt-lg-3 and pl-lg-2 class are applied. By .lg, it means from large devices/viewports. The left padding is 2 and top padding is 3.
Finally, the last paragraph is given the padding classes for extra large viewports. The classes are pt-xl-5 and pl-xl-4.
For all above paragraphs, for extra small viewports, the padding remains zero. Have a look:
See online demo and code
The markup:
<div class="container">
<h3 class="text-primary">The demo of individual padding classes</h3>
<p class="pl-sm-5 bg-info text-warning">pl-sm-5</p>
<p class="pt-md-2 pl-md-3 bg-success text-warning">pt-md-2 pl-md-3</p>
<p class="pt-lg-3 pl-lg-2 bg-primary text-warning">pt-lg-3 pl-lg-2</p>
<p class="pt-xl-5 pl-xl-4 bg-secondary text-warning">pt-xl-5 pl-xl-4</p>
</div> |
Similarly, you may use the bottom and right padding individually in different elements. For example:
Bottom padding:
Right padding:
A demo of using margin classes for all directions
In the same way, you may use the Bootstrap margin utility classes for adding the space between elements. Just like padding, you may use a single class for all directions or individual classes for each direction.
The following example applies padding in all directions in four paragraphs for all viewports:
See online demo and code
The code:
<div class="container">
<h3 class="text-primary">The demo of margin classes</h3>
<p class="m-2 bg-info text-warning">m-2 </p>
<p class="m-4 bg-success text-warning">m-3</p>
<p class="m-1 bg-primary text-warning">m-1</p>
<p class="m-5 bg-secondary text-warning">m-5</p>
</div> |
Applying margin top and bottom example
The example below shows applying different margins on top and bottom between the elements. For the top margin, following classes are used:
for the bottom, these classes are used:
- mb-sm-5
- mb-sm-4
- mb-sm-2
- mb-sm-1
As .sm breakpoint is used in all these classes, so it applies to small to extra large devices. Have a look:
See online demo and code
The HTML code:
<div class="container">
<h3 class="text-primary">The demo of margin classes</h3>
<p class="mt-sm-3 mb-sm-5 bg-info text-warning">mt-sm-1 mb-sm-5 </p>
<p class="mt-sm-2 mb-sm-4 bg-success text-warning">mt-sm-2 mb-sm-4</p>
<p class="mt-sm-4 mb-sm-2 bg-primary text-warning">mt-sm-4 mb-sm-2</p>
<p class="mt-sm-3 mb-sm-1 bg-secondary text-warning">mt-sm-3 mb-sm-1</p>
</div> |
Using x and y for margins
This example shows using the x and y for the margin sides. Just to remind the ‘x’ side will set the margin for left and right whereas the ‘y’ side sets the margins for top and bottom. Use these if you require setting the same margins for respective sides. See the usage below:
See online demo and code
The code:
<div class="container">
<h3 class="text-primary">The demo of margin classes</h3>
<p class="mx-sm-3 my-sm-5 bg-info text-warning">mx-sm-3 my-sm-5</p>
<p class="mx-sm-2 my-sm-4 bg-success text-warning">mx-sm-2 my-sm-4</p>
<p class="mx-sm-4 my-sm-2 bg-primary text-warning">mx-sm-4 my-sm-2</p>
<p class="mx-sm-3 my-sm-1 bg-secondary text-warning">mx-sm-3 my-sm-1</p>
</div> |
Grab the complete code from the example page.
Similar news:
- Naturenics website
- Authentic tapestries
- Calcium carbonate drugs
- Baja miata kit
- Deathstep music
- B8 rs5 supercharger
- Taran tactical stippling
- Jlab audio logo
- Justgive login
Such a mutual high. Oddly enough, but the ass generally responded well, it does not hurt, maybe it was because the oil was like that, or maybe because when he entered. Me, I passed out for a couple of seconds and did not feel the pain that some feel. S In the next story I will describe the second day, it will not be as long as this one, because this "story" is kind of like a confession.
My name is Rita, I am a petite brunette with a second breast size and a raised, elastic ass.