How to add background color to a div in Bootstrap ?
Bootstrap provides many classes to set the background color of an element. We can easily set the background of an element to any contextual class. Anchor components will darken on hover, just like the text classes. Some classes of background colors are listed below example.
We can add background color to a div by simply adding class “bg-primary”, “bg-success”, “bg-danger”, “bg-info”, and many more as shown in the following examples.
Step by step guide for the implementation:
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css”>
Step 2: Add <div> tag in the HTML body with class container.
Example 1: The following example shows different background-color classes to set the background color of a content.
Example 2: The following example shows how to add background color and other classes to HTML div.
- First, find the div in your HTML code and add a predefined class to the opening tag.
- Add a Bootstrap predefined class to the div you would like to change.