How to change Hamburger Toggler color in Bootstrap ?
Last Updated :
12 Sep, 2024
Changing the Hamburger Toggler color in Bootstrap refers to customizing the color of the toggle button icon used in responsive navigation menus. This involves altering the default styles of the toggler using CSS to match the design requirements, enhancing the visual appearance and brand consistency.
The hamburger toggler color can be changed in Bootstrap by using 2 methods:
Method 1: Using the inbuilt color classes
Using Bootstrap's inbuilt color classes, you can change the Hamburger Toggler color by adding utility classes like text-primary, text-danger, or text-dark to the toggler element. These classes apply predefined color styles directly to the toggler icon.
- .navbar-light: This class is used to set the color of the navigation bar content to dark. It will change the toggler icon to have darker lines.
- .navbar-dark: This class is used to set the color of the navigation bar content to light. It will change the toggler icon to have white lines.
Note: The naming seems a little backwards. Shouldn't it be .navbar-dark to make the content darker and .navbar-light to make it lighter? The -dark and -light represent the color of the background, not of the content on the navbar.
Example: In this example we demonstrates Bootstrap's light and dark navbar togglers. It uses Bootstrap's default styling for the hamburger toggler icons and includes links for both light and dark navigation bars.
html
<!DOCTYPE html>
<html>
<head>
<title>
How to change Hamburger Toggler color in Bootstrap ?
</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-light bg-lignt">
<a href="/" class="navbar-brand">
Light Toggler
</a>
<button class="navbar-toggler ml-auto"
type="button"
data-toggle="collapse"
data-target="#nav1">
<span class="navbar-toggler-icon my-toggler">
</span>
</button>
<div class="navbar-collapse collapse" id="nav1">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
</ul>
</div>
</nav>
<nav class="navbar navbar-dark bg-dark">
<a href="/" class="navbar-brand">
Dark Toggler
</a>
<button class="navbar-toggler ml-auto"
type="button"
data-toggle="collapse"
data-target="#nav2">
<span class="navbar-toggler-icon">
</span>
</button>
<div class="navbar-collapse collapse" id="nav2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<h1 style="color: green">
GeeksforGeeks
</h1>
<b>How to change Hamburger Toggler
color in Bootstrap ?</b>
<p>The above togglers use the default
color classes available for toggler.</p>
</div>
<script src=
"https://code.jquery.com/jquery-3.2.1.slim.min.js">
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js">
</script>
<script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js">
</script>
</body>
</html>
Output: 
Method 2: Creating a custom class for the toggler
Creating a custom class for the toggler involves defining your own CSS styles for the Hamburger Toggler button. By adding a custom class to the toggler element, you can specify colors, sizes, and other properties to match your design preferences.
/* Change the color in the stroke property of the image data */ .custom-toggler .navbar-toggler-icon { background-image: url("data:image/svg+xml;charset=utf8, %3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 128, 0, 0.8)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E"); }
The border color of the toggler set by specifying the border-color property with the color required.
html
/* Set the border color to the desired color */
.custom-toggler.navbar-toggler {
border-color: lightgreen;
}
Example: In this example we demonstrates customizing the Bootstrap hamburger toggler. It changes the toggler's border color to light green and uses an SVG image to set the stroke color of the icon to green.
html
<!DOCTYPE html>
<html>
<head>
<title>How to change Hamburger
Toggler color in Bootstrap ?</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
/* Set the border color */
.custom-toggler.navbar-toggler {
border-color: lightgreen;
}
/* Setting the stroke to green using rgb values (0, 128, 0) */
.custom-toggler .navbar-toggler-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32'
xmlns='http://www.w3.org/2000/svg' %3E%3Cpath stroke='rgba(0, 128, 0, 0.8)'
stroke-width='2' stroke-linecap='round' stroke-miterlimit='10'
d='M4 8h24M4 16h24M4 24h24' /%3E%3C/svg%3E");
}
</style>
</head>
<body>
<nav class="navbar navbar-dark bg-dark">
<a href="/" class="navbar-brand">Custom Toggler</a>
<button class="navbar-toggler ml-auto custom-toggler"
type="button"
data-toggle="collapse"
data-target="#nav3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="nav3">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<h1 style="color: green">GeeksforGeeks</h1>
<b>How to change Hamburger Toggler color in Bootstrap ?</b>
<p>The above togglers use the a custom classes for the toggler.</p>
</div>
<script src=
"https://code.jquery.com/jquery-3.2.1.slim.min.js">
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js">
</script>
<script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js">
</script>
</body>
</html>
Output: 
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read