Many utility/helper classes in Bootstrap 4 allow you to easily customize items without writing any CSS code.
Borders
To add or remove borders from an element, use the borderclasses:
Example
Example
Border Color
Use any of the contextual border color classes to add a color to the border:
Example
Example
Border Radius
Using the rounded classes, give an element rounded corners:
Example
Example
Float and Clearfix
Use the .float-right or .float-left classes to float an element to the right or left, then use the .clearfix class to clear floats:
Example
Example
Float leftFloat right
Responsive Floats
Use the responsive float classes (.float-*-left|right), where * is sm (>=576px), md (>=768px), lg(>=992px), or xl (>=1200px), to float an element to the left or right based on screen width:
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
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
Center Align
Using the .mx-auto class to center an element adds margin-left and margin-right: auto:
Example
Centered
Example
Centered
Width
Use the w-* classes (.w-25,.w-50,.w-75,.w-100,.mw-100) to set an element’s width:
Example
Width 25%
Width 50%
Width 75%
Width 100%
Max Width 100%
Example
Width 25%
Width 50%
Width 75%
Width 100%
Max Width 100%
Height
Use the h-* classes (.h-25,.h-50,.h-75,.h-100,.mh-100) to set an element’s height:
Example
Example
Height 25%
Height 50%
Height 75%
Height 100%
Max Height 100%
Spacing
Bootstrap 4 provides a large range of responsive margin and padding utility classes. All breakpoints (xs (<=576px), sm (>=576px), md (>=768px), lg (>=992px), or xl (>=1200px) are supported by them.
For xs, the classes are used in the following format: {property}{sides}-{size}, and for sm, md, lg, and xl, {property}{sides}–{breakpoint}-{size}.
In cases when property is one of:
m – sets margin
p– sets padding
Where one of the sides is:
t – sets margin-top or padding-top
b – sets margin-bottom or padding-bottom
l – sets margin-left or padding-left
r– sets margin-right or padding-right
x – sets both padding-leftand padding-right or margin-left and margin-right
y – sets both padding-top and padding-bottom or margin-topand margin-bottom
blank – sets a marginor paddingon all 4 sides of the element
Size is one of:
0 – sets marginor paddingto 0
1 – sets marginor paddingto .25rem (4px if font-size is 16px)
2 – sets marginor paddingto .5rem (8px if font-size is 16px)
3 – sets marginor paddingto 1rem (16px if font-size is 16px)
4 – sets marginor paddingto 1.5rem (24px if font-size is 16px)
5 – sets marginor paddingto 3rem (48px if font-size is 16px)
auto – sets marginto auto
Note: By placing a “n” in front of size, margins can also be negative:
n1 – sets marginto -.25rem(-4px if font-size is 16px)
n2 – sets marginto -.5rem (-8px if font-size is 16px)
n3 – sets marginto -1rem (-16px if font-size is 16px)
n4 – sets marginto -1.5rem (-24px if font-size is 16px)
n5 – sets marginto -3rem (-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
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)
To apply shadows to an element, use the shadow-classes:
Example
No shadow
Small shadow
Default shadow
Large shadow
Example
No shadow
Small shadow
Default shadow
Large shadow
Vertical Align
To alter an element’s alignment, use the align-classes (which are limited to inline, inline-block, inline-table, and table cell elements):
Example
baselinetopmiddlebottomtext-toptext-bottom
Example
baselinetopmiddlebottomtext-toptext-bottom
Responsive Embeds
Make responsive embeds for slideshows or videos according to the parent’s width.
To any embed element (such as <iframe> or <video>), add the .embed-responsive-item in a parent element with .embed-responsive and any desired aspect ratio:
Example
Visibility
To manage an element’s visibility, use the .visible or .invisibleclasses.
Note: The CSS display value is not altered by these classes. Only visibility:visible and visibility:hidden are added by them.
Example
I am visible
Example
I am visible
I am invisible
Position
To make any element stay at the top of the page or become fixed, use the .fixed-top class:
==== Example MUKAVU ====
Example
...
To make any element stay at the bottom of the page or become fixed, use the .fixed-bottom class:
==== Example MUKAVU ====
Example
...
To make any element fixed or stay at the top of the page when you scroll past it, use the .sticky-top class. Note: IE11 and older versions of this class will treat it as position:relative and will not function.
==== Example MUKAVU ====
Example
...
Close icon
To customize a closing icon, use the .closeclass. This is frequently applied to modals and alarms. Take note that to make the actual icon (a prettier “x”), we use the × symbol. Remember that it floats right by default as well.
Example
×
Example
Screenreaders
Use the .sr-onlyclass to hide an element on all devices, except screen readers:
Example
I will be hidden on all screens except for screen readers.
Colors
Here is a list of all the text and background color classes, as explained in the Colors chapter:
Text-muted, .text-primary, .text-success, .text-info, .text-warning, .text-danger, .text-secondary, .text-white, .text-dark, .text-body (default body color/often black), and .text-light are the classes for text colors:
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.
Links can also be used with contextual text classes, which will add a darker hover color:
With the .text-black-50 or .text-white-50classes, you may additionally apply 50% opacity to black or white text:
Example
Black text with 50% opacity on white background
White text with 50% opacity on black background
Background Colors
.bg-primary,.bg-success ,.bg-info,.bg-warning,.bg-danger,.bg-secondary,.bg-dark, and .bg-light are the classes for background colors.
Keep in mind that background colors do not change the text color, so you may wish to combine them with a .text-* class in some situations.
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
Here is a list of all typography/text classes, as explained in the Typography chapter:
Class
Description
Example
.display-*
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: .display-1, .display-2, .display-3, .display-4
Removes the default list-style and left margin on list items (works on both <ul> and <ol>). 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)
Add the .d-blockclass to an element to turn it into a block element. To specify WHEN the element should be a block element on a given screen width, use any of the d-*-block classes: