Bootstrap Q&A Logo
Bootstrap Q&A Part of the Q&A Network
Q&A Logo

What's the best way to customize the color of a Bootstrap navbar background?

Asked on Oct 04, 2025

Answer

To customize the color of a Bootstrap navbar background, you can use custom CSS classes to override the default styles. Here's a simple example of how to do this using Bootstrap 5.
<!-- BEGIN COPY / PASTE -->
        <nav class="navbar navbar-expand-lg" style="background-color: #4CAF50;">
            <div class="container-fluid">
                <a class="navbar-brand" href="#">Brand</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav">
                        <li class="nav-item">
                            <a class="nav-link active" aria-current="page" href="#">Home</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Features</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Pricing</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
        <!-- END COPY / PASTE -->
Additional Comment:
  • You can change the `background-color` property in the `style` attribute to any color you prefer.
  • This example uses an inline style for simplicity, but you can also define a CSS class in a separate stylesheet for better maintainability.
  • Ensure that the text color contrasts well with the background color for accessibility.
✅ Answered with Bootstrap 5 best practices.
← Back to All Questions