- Published on
6 Easy Ways To Make A Github Navbar Searchbox With Tailwind CSS

- What is Tailwind CSS?
- The description of Github navbar searchbox ui component
- Why use Tailwind CSS to build a Github navbar searchbox ui component?
- The preview of Github navbar searchbox ui component
- The source code of Github navbar searchbox ui component
- How to build a Github navbar searchbox with Tailwind CSS?
- Install tailwind css of verion 2.0.1
- All the unility class needed to build a Github navbar searchbox component
- 83 steps to build a Github navbar searchbox 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 Github navbar searchbox ui component
The poor way to simulate github search box
Why use Tailwind CSS to build a Github navbar searchbox ui component?
- It can make the building process of Github navbar searchbox ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Github navbar searchbox component file.
The preview of Github navbar searchbox ui component
Free download of the Github navbar searchbox's source code
The source code of Github navbar searchbox ui component
<style>
[x-cloak]{
display: none;
}
</style>
<div class="min-h-screen">
<nav class="py-1 text-white bg-gray-900 md:py-2 md:flex md:items-center" x-data="navbar()" x-init="init($el)">
<div class="flex items-center justify-between p-2">
<!-- Menu button -->
<button @click="toggleNavbar" class="p-1 text-gray-300 rounded-md md:hidden focus:outline-none focus:ring">
<svg class="w-8 h-8" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
<!-- Logo -->
<a
href="https://github.com/Kamona-WD"
target="_blank"
class="inline-block text-2xl font-semibold tracking-wider text-gray-200 uppercase md:ml-3"
>
K-WD
</a>
<!-- Notification button -->
<a href="#" class="p-1 text-gray-300 rounded-md md:hidden focus:outline-none focus:ring">
<svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"
/>
</svg>
</a>
</div>
<div
:class="{'overflow-hidden max-h-0': !isOpen}"
class="md:max-h-full md:flex md:items-center md:overflow-visible md:flex-1"
>
<!-- Search -->
<div class="relative w-full md:max-w-max">
<form action="#" class="px-3 md:px-0">
<label class="relative">
<input
id="searchInput"
type="text"
placeholder="Search or jump to..."
x-model="searchQuery"
@focus="openSearchBox"
@blur="closeSearchBox"
autocomplete="off"
@keydown="startSearching"
class="w-full px-2 py-1 text-gray-700 transition-all bg-gray-900 border border-gray-600 rounded-md focus:outline-none focus:bg-gray-200"
:class="{'md:w-60 lg:w-96': isSearchBoxOpen, 'md:w-60':!isSearchBoxOpen}"
/>
<span
x-show="!isSearchBoxOpen"
class="absolute inset-y-0 flex items-center justify-center px-2 py-1 text-xs text-gray-500 border border-gray-500 rounded-md right-2"
>/</span
>
</label>
</form>
<div x-show="isSearchBoxOpen" class="absolute inset-x-0 px-3 -mt-1 md:px-0" x-cloak>
<div class="mx-px bg-white shadow-md rounded-b-md">
<div x-show="loading" class="flex items-center justify-center">
<h1 class="text-gray-600">Loading...</h1>
</div>
<div x-show="!loading" class="bg-white">
<ul>
<li x-show="searchQuery.length">
<a
href="#"
id="ss"
class="flex items-center p-2"
:class="{'text-white bg-blue-700': isTyping, 'text-gray-600': !isTyping}"
@mouseleave="isTyping=false"
@mouseenter="isTyping=true"
>
<!-- Search icon -->
<span>
<svg
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
</span>
<span class="ml-2 text-sm truncate" x-text="searchQuery"></span>
<span
class="inline-block px-2 py-1 ml-auto text-xs bg-white rounded-md"
:class="{'text-gray-600': isTyping, 'text-white': !isTyping}"
>All Github</span
>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-600 group hover:bg-blue-700 hover:text-white">
<span>
<svg
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
/>
</svg>
</span>
<span class="ml-2 text-sm truncate">Kamona-WD/starter-dashboard-layout</span>
<span
class="inline-block px-2 py-1 ml-auto text-xs text-white bg-white rounded-md whitespace-nowrap group-hover:text-gray-600"
>Jumb to</span
>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-600 group hover:text-white hover:bg-blue-700">
<span>
<svg
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
/>
</svg>
</span>
<span class="ml-2 text-sm truncate">Kamona-WD/fortify-bootstrap</span>
<span
class="inline-block px-2 py-1 ml-auto text-xs text-white bg-white rounded-md whitespace-nowrap group-hover:text-gray-600"
>Jumb to</span
>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-600 group hover:text-white hover:bg-blue-700">
<span>
<svg
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
/>
</svg>
</span>
<span class="ml-2 text-sm truncate">Kamona-WD/fortify-windmill</span>
<span
class="inline-block px-2 py-1 ml-auto text-xs text-white bg-white rounded-md whitespace-nowrap group-hover:text-gray-600"
>Jumb to</span
>
</a>
</li>
<li>
<a href="#" class="flex items-center p-2 text-gray-600 group hover:text-white hover:bg-blue-700">
<span>
<svg
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
/>
</svg>
</span>
<span class="ml-2 text-sm truncate">Kamona-WD/tailwindcss-directions</span>
<span
class="inline-block px-2 py-1 ml-auto text-xs text-white bg-white rounded-md whitespace-nowrap group-hover:text-gray-600"
>Jumb to</span
>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Links -->
<ul
class="mx-3 mt-4 border-t border-gray-700 divide-y divide-gray-700 md:mx-1 md:flex md:items-center md:space-x-1 md:border-none md:divide-y-0 md:mt-0"
>
<li class="md:hidden">
<a
href="#"
class="inline-flex py-2 font-medium transition-colors md:p-2 md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>Dashboard</a
>
</li>
<li class="">
<a
href="#"
class="inline-flex py-2 font-medium transition-colors md:text-sm whitespace-nowrap md:p-1 md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>Pull requests</a
>
</li>
<li class="">
<a
href="#"
class="inline-flex py-2 font-medium transition-colors md:text-sm whitespace-nowrap md:p-1 md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>Issues</a
>
</li>
<li class="">
<a
href="#"
class="inline-flex py-2 font-medium transition-colors md:text-sm whitespace-nowrap md:p-1 md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>Marketplace</a
>
</li>
<li class="">
<a
href="#"
class="inline-flex py-2 font-medium transition-colors md:text-sm whitespace-nowrap md:p-1 md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>Explore</a
>
</li>
<li class="md:hidden">
<a
href="#"
class="inline-flex py-2 font-medium transition-colors md:p-1 md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>Settings</a
>
</li>
</ul>
<ul class="flex-shrink-0 mx-3 md:ml-auto md:px-3 md:flex md:items-center md:space-x-2">
<li class="hidden md:block">
<a href="#" class="text-gray-300 rounded-md focus:outline-none focus:ring">
<svg
class="w-5 h-5"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"
/>
</svg>
</a>
</li>
<li class="hidden md:block">
<a href="#" class="flex items-center rounded-md focus:outline-none focus:ring">
<span class="">
<!-- plus icon -->
<svg
class="w-6 h-6 text-gray-300"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
/>
</svg>
</span>
<span
class="inline-block w-0 h-0"
style="
vertical-align: middle;
content: '';
border-top-style: solid;
border-top-width: 4px;
border-right: 4px solid transparent;
border-bottom: 0 solid transparent;
border-left: 4px solid transparent;
"
></span>
</a>
</li>
<li>
<a
href="#"
class="flex items-center md:rounded-md hover:text-gray-400 focus:text-gray-400 focus:outline-none md:focus:ring"
>
<img
class="w-5 h-5 rounded-full"
src="https://avatars0.githubusercontent.com/u/57622665?s=400&u=8f581f4c4acd4c18c33a87b3e6476112325e8b38&v=4"
alt="Kamona-WD"
/>
<span class="ml-2 md:hidden">Kamona-WD</span>
<span
class="hidden w-0 h-0 md:inline-block md:ml-1"
style="
vertical-align: middle;
content: '';
border-top-style: solid;
border-top-width: 4px;
border-right: 4px solid transparent;
border-bottom: 0 solid transparent;
border-left: 4px solid transparent;
"
></span>
</a>
</li>
<li class="py-2 md:hidden">
<a href="#" class="flex items-center space-x-2">
<svg
class="w-5 h-5"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
/>
</svg>
<span>Logout</span>
</a>
</li>
</ul>
</div>
</nav>
<main class="m-12">
<p>The poor way to simulate github search box</p>
<p class="mt-6">Press '/' to search</p>
<div class="inline-flex flex-col mt-6 space-y-2">
<a href="https://github.com/Kamona-WD" target="_blank" class="text-blue-800 hover:underline"
>Github account</a
>
<a href="https://twitter.com/ak_kamona" target="_blank" class="text-blue-800 hover:underline"
>Twitter account</a
>
</div>
</main>
</div>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js"></script>
<script>
function handleKeydown(el, event) {
if (event.keyCode == 191) {
event.preventDefault()
el.querySelector('#searchInput').focus()
}
if (event.keyCode == 27) {
el.querySelector('#searchInput').blur()
}
}
function init(el) {
document.addEventListener('keydown', handleKeydown.bind(null, el), false)
}
function navbar() {
return {
isOpen: false,
toggleNavbar() {
this.isOpen = !this.isOpen
},
isSearchBoxOpen: false,
isSearching: false,
loading: false,
isTyping: false,
searchQuery: '',
openSearchBox() {
this.isSearchBoxOpen = true
this.loading = true
setTimeout(() => {
this.loading = false
}, 500)
},
closeSearchBox() {
this.isSearchBoxOpen = false
},
startSearching() {
this.isTyping = true
},
}
}
</script>
How to build a Github navbar searchbox with Tailwind CSS?
Install tailwind css of verion 2.0.1
Use the script
html tag to import the script of Tailwind CSS of the version 2.0.1
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to build a Github navbar searchbox component
min-h-screen
py-1
text-white
bg-gray-900
md:py-2
md:flex
flex
p-2
p-1
text-gray-300
md:hidden
w-8
h-8
inline-block
text-2xl
text-gray-200
md:ml-3
w-5
h-5
overflow-hidden
max-h-0
md:max-h-full
md:overflow-visible
md:flex-1
relative
w-full
md:max-w-max
px-3
md:px-0
px-2
text-gray-700
border-gray-600
focus:bg-gray-200
md:w-60
lg:w-96
md:w-60':!isSearchBoxOpen}
absolute
text-xs
text-gray-500
border-gray-500
right-2
-mt-1
mx-px
bg-white
text-gray-600
bg-blue-700
w-4
h-4
ml-2
text-sm
ml-auto
hover:bg-blue-700
hover:text-white
group-hover:text-gray-600
mx-3
mt-4
border-t
border-gray-700
md:mx-1
md:border-none
md:mt-0
inline-flex
py-2
md:p-2
hover:text-gray-400
focus:text-gray-400
md:text-sm
md:p-1
flex-shrink-0
md:ml-auto
md:px-3
hidden
md:block
w-6
h-6
w-0
h-0
md:inline-block
md:ml-1
m-12
mt-6
flex-col
text-blue-800
83 steps to build a Github navbar searchbox component with Tailwind CSS
Set the minimum width/height of an element using the
min-h-screen
utilities.Control the vertical padding of an element to 0.25rem using the
py-1
utilities.Control the text color of an element to white using the
text-white
utilities.Control the background color of an element to gray-900 using the
bg-gray-900
utilities.Control the vertical padding of an element to 0.5rem at only medium screen sizes using the
md:py-2
utilities.Use
flex
to create a block-level flex container at only medium screen sizes.Use
flex
to create a block-level flex container.Control the padding on all sides of an element to 0.5rem using the
p-2
utilities.Control the padding on all sides of an element to 0.25rem using the
p-1
utilities.Control the text color of an element to gray-300 using the
text-gray-300
utilities.Use
hidden
to set an element to display: none and remove it from the page layout at only medium screen sizes.Use
w-8
to set an element to a fixed width(2rem).Use
h-8
to set an element to a fixed height(2rem).Use
inline-block
utilities to wrap the element to prevent the text inside from extending beyond its parent.Control the text color of an element to 2xl using the
text-2xl
utilities.Control the text color of an element to gray-200 using the
text-gray-200
utilities.Control the margin on left side of an element to 0.75rem at only medium screen sizes using the
md:ml-3
utilities.Use
w-5
to set an element to a fixed width(1.25rem).Use
h-5
to set an element to a fixed height(1.25rem).Use
overflow-hidden
to clip any content within an element that overflows the bounds of that element.Set the maximum width/height of an element using the
max-h-0
utilities.Set the maximum width/height of an element using the
md:max-h-full
utilities at only medium screen sizes.Use
overflow-visible
to prevent content within an element from being clipped at only medium screen sizes. Note that any content that overflows the bounds of the element will then be visible.Use
flex
to create a block-level flex container at only medium screen sizes.Use
relative
to position an element according to the normal flow of the document.Use
w-full
to set an element to a 100% based width.Set the maximum width/height of an element using the
md:max-w-max
utilities at only medium screen sizes.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the horizontal padding of an element to 0rem at only medium screen sizes using the
md:px-0
utilities.Control the horizontal padding of an element to 0.5rem using the
px-2
utilities.Control the text color of an element to gray-700 using the
text-gray-700
utilities.Control the border color of an element to gray-600 using the
border-gray-600
utilities.Control the background color of an element to gray-200 using the
focus:bg-gray-200
utilities on focus.Use
md:w-60
to set an element to a fixed width(15rem) at only medium screen sizes.Use
lg:w-96
to set an element to a fixed width(24rem) at only large screen sizes.Use
md:w-60':!isSearchBoxOpen}
to set an element to a fixed width(60') at only medium screen sizes.Use
absolute
to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.Control the text color of an element to xs using the
text-xs
utilities.Control the text color of an element to gray-500 using the
text-gray-500
utilities.Control the border color of an element to gray-500 using the
border-gray-500
utilities.Use the
right-2
utilities to set the right position of a positioned element to 0.5rem.Control the margin on top side of an element to -0.25rem using the
-mt-1
utilities.Control the horizontal margin of an element to px using the
mx-px
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the text color of an element to gray-600 using the
text-gray-600
utilities.Control the background color of an element to blue-700 using the
bg-blue-700
utilities.Use
w-4
to set an element to a fixed width(1rem).Use
h-4
to set an element to a fixed height(1rem).Control the margin on left side of an element to 0.5rem using the
ml-2
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the margin on left side of an element to auto using the
ml-auto
utilities.Control the background color of an element to blue-700 using the
hover:bg-blue-700
utilities on hover.Control the text color of an element to white on hover using the
hover:text-white
utilities.Control the text color of an element to gray-600undefined using the
group-hover:text-gray-600
utilities.Control the horizontal margin of an element to 0.75rem using the
mx-3
utilities.Control the margin on top side of an element to 1rem using the
mt-4
utilities.Control the border color of an element to t using the
border-t
utilities.Control the border color of an element to gray-700 using the
border-gray-700
utilities.Control the horizontal margin of an element to 0.25rem at only medium screen sizes using the
md:mx-1
utilities.Control the border color of an element to none using the
md:border-none
utilities at only medium screen sizes.Control the margin on top side of an element to 0rem at only medium screen sizes using the
md:mt-0
utilities.Use
inline-flex
to create an inline flex container that flows with text.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the padding on all sides of an element to 0.5rem at only medium screen sizes using the
md:p-2
utilities.Control the text color of an element to gray-400 on hover using the
hover:text-gray-400
utilities.Control the text color of an element to gray-400 on focus using the
focus:text-gray-400
utilities.Control the text color of an element to sm at only medium screen sizes using the
md:text-sm
utilities.Control the padding on all sides of an element to 0.25rem at only medium screen sizes using the
md:p-1
utilities.Use
flex
to create a block-level flex container.Control the margin on left side of an element to auto at only medium screen sizes using the
md:ml-auto
utilities.Control the horizontal padding of an element to 0.75rem at only medium screen sizes using the
md:px-3
utilities.Use
hidden
to set an element to display: none and remove it from the page layout.Use
inline
utilities to put the element on its own line and fill its parent at only medium screen sizes.Use
w-6
to set an element to a fixed width(1.5rem).Use
h-6
to set an element to a fixed height(1.5rem).Use
w-0
to set an element to a fixed width(0rem).Use
h-0
to set an element to a fixed height(0rem).Use
inline-block
utilities to wrap the element to prevent the text inside from extending beyond its parent at only medium screen sizes.Control the margin on left side of an element to 0.25rem at only medium screen sizes using the
md:ml-1
utilities.Control the margin on all sides of an element to 3rem using the
m-12
utilities.Control the margin on top side of an element to 1.5rem using the
mt-6
utilities.Use
flex
to create a block-level flex container.Control the text color of an element to blue-800 using the
text-blue-800
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to build a Github navbar searchbox components, learn and follow along to implement your own components.