How to Create a Navigation Bar with Icons in Tailwind CSS ?
Last Updated :
14 Mar, 2024
A navigation bar, commonly known as a nav bar, serves as a fundamental component of user interface design, facilitating seamless navigation across a website or application. Using the icons in the navigation bar gains a distinctive advantage in visual communication. Icons streamline navigation by using universally recognized symbols instead of lengthy textual labels.
Approach:
- Utilize Bootstrap’s navbar component to create a responsive navigation bar.
- Use the ‘navbar-brand’ class for the logo and ‘navbar-toggler’ for the collapsible button on smaller screens.
- Incorporate icons from Font Awesome using <i> tags within the <a> elements for each navigation item.
- Ensure proper alignment and spacing with Bootstrap’s utility classes and grid system.
Example: Implementation to create a navigation bar with Icons in Tailwind CSS.
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>
Fixed Collapsing Navbar in Bootstrap 5
</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light fs-5">
<div class="container">
<a class="navbar-brand"
href="https://www.geeksforgeeks.org/">
<img src=
"https://media.geeksforgeeks.org/gfg-gg-logo.svg"
class="rounded float-start">
</a>
<!-- Toggler button for small screens -->
<button class="navbar-toggler" type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collapsible content -->
<div class="collapse navbar-collapse"
id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active text-success"
aria-current="page" href="#">
<i class="fas fa-home"></i> Home
</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#">
<i class="fas fa-user"></i> About
</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#">
<i class="fas fa-briefcase"></i> Services
</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#">
<i class="fas fa-envelope"></i> Contact
</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search"
placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">
Search
</button>
</form>
</div>
</div>
</nav>
<link href=
"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
rel="stylesheet">
<script src=
"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js">
</script>
<link href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"
rel="stylesheet">
</body>
</html>
Output:
Share your thoughts in the comments
Please Login to comment...