- Published on
The 5 Really Obvious Ways To Make A side nav bar With Tailwind CSS Better That You Ever Did

- What is Tailwind CSS?
- The description of side nav bar ui component
- Why use Tailwind CSS to create a side nav bar ui component?
- The preview of side nav bar ui component
- The source code of side nav bar ui component
- How to create a side nav bar with Tailwind CSS?
- Install tailwind css of verion 2.2.4
- All the unility class needed to create a side nav bar component
- 19 steps to create a side nav bar component with Tailwind CSS
- Conclusion
What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.
The description of side nav bar ui component
Simple side navigation bar.. svg from heroicons.com
Why use Tailwind CSS to create a side nav bar ui component?
- It can make the building process of side nav bar ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in side nav bar component file.
The preview of side nav bar ui component
Free download of the side nav bar's source code
The source code of side nav bar ui component
<div class="h-screen w-48 px-4 border-r bg-white">
<div class="h-3/4 flex flex-col justify-around text-gray-500">
<h3 class="pl-1 text-sm flex items-center py-2 mb-2 hover:bg-gray-100 hover:text-gray-700 transition duration-200 ease-in">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="black">
<path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z" />
</svg>
<a class="hover:text-black transition duration-200 ease-linear" href="#">Home</a>
</h3>
<h3 class="pl-1 text-sm flex items-center py-2 mb-2 hover:bg-gray-100 hover:text-gray-700 transition duration-200 ease-in">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="black">
<path d="M2 11a1 1 0 011-1h2a1 1 0 011 1v5a1 1 0 01-1 1H3a1 1 0 01-1-1v-5zM8 7a1 1 0 011-1h2a1 1 0 011 1v9a1 1 0 01-1 1H9a1 1 0 01-1-1V7zM14 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1h-2a1 1 0 01-1-1V4z" />
</svg>
<a class="hover:text-black transition duration-200 ease-linear" href="#">Dashboard</a>
</h3>
<h3 class="pl-1 text-sm flex items-center py-2 mb-2 hover:bg-gray-100 hover:text-gray-700 transition duration-200 ease-in">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="black">
<path d="M2 5a2 2 0 012-2h7a2 2 0 012 2v4a2 2 0 01-2 2H9l-3 3v-3H4a2 2 0 01-2-2V5z" />
<path d="M15 7v2a4 4 0 01-4 4H9.828l-1.766 1.767c.28.149.599.233.938.233h2l3 3v-3h2a2 2 0 002-2V9a2 2 0 00-2-2h-1z" />
</svg>
<a class="hover:text-black transition duration-200 ease-linear" href="#">Comments</a>
</h3>
<h3 class="pl-1 text-sm flex items-center py-2 mb-2 hover:bg-gray-100 hover:text-gray-700 transition duration-200 ease-in">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="black">
<path fill-rule="evenodd" d="M5 3a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2V5a2 2 0 00-2-2H5zm0 2h10v7h-2l-1 2H8l-1-2H5V5z" clip-rule="evenodd" />
</svg>
<a class="hover:text-black transition duration-200 ease-linear" href="#">Inbox</a>
</h3>
<h3 class="pl-1 text-sm flex items-center py-2 mb-2 hover:bg-gray-100 hover:text-gray-700 transition duration-200 ease-in">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="black">
<path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd" />
</svg>
<a class="hover:text-black transition duration-200 ease-linear" href="#">Profile</a>
</h3>
<h3 class="pl-1 text-sm flex items-center py-2 mb-2 hover:bg-gray-100 hover:text-gray-700 transition duration-200 ease-in">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="black">
<path fill-rule="evenodd" d="M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z" clip-rule="evenodd" />
</svg>
<a class="hover:text-black transition duration-200 ease-linear" href="#">Settings</a>
</h3>
</div>
</div>
How to create a side nav bar with Tailwind CSS?
Install tailwind css of verion 2.2.4
Use the script
html tag to import the script of Tailwind CSS of the version 2.2.4
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to create a side nav bar component
h-screen
w-48
px-4
border-r
bg-white
h-3/4
flex
flex-col
text-gray-500
pl-1
text-sm
py-2
mb-2
hover:bg-gray-100
hover:text-gray-700
h-5
w-5
mr-2
hover:text-black
19 steps to create a side nav bar component with Tailwind CSS
Use
h-screen
to make an element span the entire height of the viewport.Use
w-48
to set an element to a fixed width(12rem).Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the border color of an element to r using the
border-r
utilities.Control the background color of an element to white using the
bg-white
utilities.Use
h-3/4
to set an element to a fixed height(3/4).Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Control the text color of an element to gray-500 using the
text-gray-500
utilities.Set the left padding of the element to 0.25rem using the
pl-1
utilities classControl the text color of an element to sm using the
text-sm
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the margin on bottom side of an element to 0.5rem using the
mb-2
utilities.Control the background color of an element to gray-100 using the
hover:bg-gray-100
utilities on hover.Control the text color of an element to gray-700 on hover using the
hover:text-gray-700
utilities.Use
h-5
to set an element to a fixed height(1.25rem).Use
w-5
to set an element to a fixed width(1.25rem).Control the margin on right side of an element to 0.5rem using the
mr-2
utilities.Control the text color of an element to black on hover using the
hover:text-black
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to create a side nav bar components, learn and follow along to implement your own components.