One way to make our websites or projects look attractive is to add some colors to them. The right choices of colors can be very important for efficiently conveying our messages.
Bootstrap 4 has some predefined contextual classes we can use to change the color of the text or the background of our elements.
These classes are divided into two main types:
Here are the classes that can give different colors to our text to convey different messages.
Text colors | Classes |
Primary text |
|
Secondary text |
|
Success |
|
Warning |
|
Danger/Alert |
|
Dark |
|
White |
|
Light |
|
Information |
|
Body |
|
Muted |
|
To use any of the above classes, we add the class inside the element tag. For instance, we can use the <p>
or <h>
tag. Here, we use the <h4>
tag.
<h4> Important Text</h4>
Now, let’s discuss the different colors in Bootstrap through an example.
head
tags.h4
.Here are the classes we can use to add background colors in Bootstrap.
Background Colors | Classes |
Primary background |
|
Secondary background |
|
Success background |
|
Warning background |
|
Danger/alert background |
|
Dark background |
|
Light background |
|
Information background |
|
To use any of the above classes, we add the desired class inside the element tag. Here, we use bg-primary
.
<h5> Primary background</h5>
bg-dark
class in combination with the text-white
class. This gives us a dark grey background with white text.Note: Background color classes do not have any impact on the text color. So, we can change the background and text colors simultaneously.