07 Oct Bootstrap – Change the Text Background Color on a web page
Learn how to set the background color for text on a web page using the contextual classes in Bootstrap with live running examples. The following are the Contextual Classes to change the background color:
- .bg-primary: key information
- .bg-success: success action
- .bg-info: set information
- .bg-warning: set warning message
- .bg-danger: set danger message
- .bg-secondary: less important info
- .bg-dark: dark background color
- .bg-light: light background color
Example – Change the Text Background Color
Let us now see an example to change the background color for text in Bootstrap:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Background Color Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="container"> <h2>Text Background</h2> <p class="bg-primary">This is example text</p> <p class="bg-warning">This is example text</p> <p class="bg-danger">This is example text</p> <p class="bg-info">This is example text</p> <p class="bg-secondary">This is example text</p> <p class="bg-success">This is example text</p> <p class="bg-dark text-white">This is example text</p> <p class="bg-light">This is example text</p> </div> </body> </html> |
Output
Video Tutorial – Change Text Background Color
The following is the complete video tutorial to learn how to change the text background color in Bootstrap:
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:
Read More:
No Comments