A navbar helps users move around a website. Changing its color makes it easy to match your website style and improve visibility.
Navbar color schemes in Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <!-- Navbar content --> </nav> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <!-- Navbar content --> </nav>
Use navbar-light with light backgrounds for dark text.
Use navbar-dark with dark backgrounds for light text.
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">Light Navbar</a> </nav>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <a class="navbar-brand" href="#">Dark Navbar</a> </nav>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <a class="navbar-brand" href="#">Primary Color Navbar</a> </nav>
This page shows three navbars with different color schemes: light, dark, and primary color. Each uses the correct navbar-light or navbar-dark class to keep text readable.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Navbar Color Schemes</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container-fluid"> <a class="navbar-brand" href="#">Light Navbar</a> </div> </nav> <nav class="navbar navbar-expand-lg navbar-dark bg-dark mt-3"> <div class="container-fluid"> <a class="navbar-brand" href="#">Dark Navbar</a> </div> </nav> <nav class="navbar navbar-expand-lg navbar-dark bg-primary mt-3"> <div class="container-fluid"> <a class="navbar-brand" href="#">Primary Color Navbar</a> </div> </nav> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Always pair navbar-light with light backgrounds and navbar-dark with dark backgrounds for good contrast.
You can use Bootstrap background color classes like bg-primary, bg-success, or bg-danger to change navbar colors easily.
Use the browser's developer tools to inspect and experiment with navbar colors live.
Navbar color schemes help match your website style and improve readability.
Use navbar-light with light backgrounds and navbar-dark with dark backgrounds.
Bootstrap provides many background color classes to customize your navbar easily.
Practice
Solution
Step 1: Understand navbar text color classes
Thenavbar-lightclass makes text dark for readability on light backgrounds.Step 2: Match class to background type
Since the background is light,navbar-lightis appropriate, unlikenavbar-darkwhich is for dark backgrounds.Final Answer:
navbar-light -> Option BQuick Check:
Light background needs dark text = navbar-light [OK]
- Confusing navbar-light with navbar-dark
- Using bg-dark instead of navbar color scheme
- Applying text-light on light backgrounds
Solution
Step 1: Identify the correct navbar text color for dark background
For dark backgrounds,navbar-darkensures text is light and readable.Step 2: Match background color class
The background classbg-darksets a dark background color.Final Answer:
<nav class='navbar navbar-dark bg-dark'> -> Option DQuick Check:
Dark background needs navbar-dark + bg-dark [OK]
- Mixing navbar-light with bg-dark
- Using bg-light with navbar-dark
- Forgetting to include both navbar and bg classes
<nav class='navbar navbar-dark bg-primary'> <a class='navbar-brand' href='#'>Brand</a> </nav>
Solution
Step 1: Understand navbar-dark effect on text
Thenavbar-darkclass makes text light-colored for contrast on dark backgrounds.Step 2: Recognize bg-primary background
bg-primaryis a dark blue background, so light text is used for readability.Final Answer:
Light text color -> Option CQuick Check:
navbar-dark + dark bg = light text [OK]
- Assuming text matches bg-primary color
- Thinking navbar-dark means dark text
- Ignoring the effect of navbar-dark on text color
<nav class='navbar navbar-light bg-dark'> <a class='navbar-brand' href='#'>Brand</a> </nav>
Solution
Step 1: Check navbar color scheme consistency
The classnavbar-lightis for light backgrounds, butbg-darksets a dark background.Step 2: Understand readability issue
This mismatch causes dark background with dark text, reducing readability.Final Answer:
Using navbar-light with a dark background -> Option AQuick Check:
navbar-light must pair with light backgrounds [OK]
- Ignoring navbar-expand necessity
- Thinking navbar-brand needs href fix
- Confusing navbar-light and navbar-dark usage
Solution
Step 1: Identify background color and text color needs
You want a light background with dark text. The green backgroundbg-successis a bright green, considered light.Step 2: Choose matching navbar text color class
For light backgrounds,navbar-lightis used to make text dark and readable.Final Answer:
navbar navbar-light bg-success -> Option AQuick Check:
Light bg (green) needs navbar-light for dark text [OK]
- Using navbar-dark with bright green background
- Choosing bg-light instead of desired green
- Mixing navbar-dark with light backgrounds
Ready to prove it?
Pass the test and this pattern moves unknown
