- Published on
Here Are 6 Ways To Build A Free Tailwind CSS Dropdown Component With Tailwind CSS

- What is Tailwind CSS?
- The description of Free Tailwind CSS Dropdown Component ui component
- Why use Tailwind CSS to make a Free Tailwind CSS Dropdown Component ui component?
- The preview of Free Tailwind CSS Dropdown Component ui component
- The source code of Free Tailwind CSS Dropdown Component ui component
- How to make a Free Tailwind CSS Dropdown Component with Tailwind CSS?
- Install tailwind css of verion 2.2.19
- All the unility class needed to make a Free Tailwind CSS Dropdown Component component
- 37 steps to make a Free Tailwind CSS Dropdown Component 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 Free Tailwind CSS Dropdown Component ui component
Tailwind dropdown offers users a list of options. when clicked, items from the list 'drop-down' and offer the user to choose from that options. find more free and premium tailwind css components at www.tailwinduikit.com
Why use Tailwind CSS to make a Free Tailwind CSS Dropdown Component ui component?
- It can make the building process of Free Tailwind CSS Dropdown Component ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Free Tailwind CSS Dropdown Component component file.
The preview of Free Tailwind CSS Dropdown Component ui component
Free download of the Free Tailwind CSS Dropdown Component's source code
The source code of Free Tailwind CSS Dropdown Component ui component
<div>
<!--- more free and premium Tailwind CSS components at https://tailwinduikit.com/ --->
<button class="focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 focus:bg-gray-100 w-64 p-4 shadow rounded bg-white text-sm font-medium leading-none text-gray-800 flex items-center justify-between cursor-pointer" onclick="dropdownHandler()">
Channels
<div>
<div class="hidden" id="close">
<svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.00016 0.666664L9.66683 5.33333L0.333496 5.33333L5.00016 0.666664Z" fill="#1F2937" />
</svg>
</div>
<div id="open">
<svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.00016 5.33333L0.333496 0.666664H9.66683L5.00016 5.33333Z" fill="#1F2937" />
</svg>
</div>
</div>
</button>
<div class="w-64 mt-2 p-4 bg-white shadow rounded" id="dropdown">
<div class="flex items-center justify-between">
<div class="flex items-center">
<svg role="button" aria-label="dropdown" tabindex="0" onclick="toggleSubDir(1)" onkeypress="toggleSubDir(1)" class="focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 rounded-md" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.5 3L7.5 6L4.5 9" stroke="#4B5563" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="fb1" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="fb1" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Facebook</p>
</div>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div id="sublist1" class="pl-8 pt-5 hidden">
<div class="flex items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="usa1" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="usa1" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">USA</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div class="flex pt-4 items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="ger1" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="ger1" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Germany</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div class="flex pt-4 items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="italy1" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="italy1" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Italy</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
</div>
<div>
<div class="flex items-center justify-between mt-4">
<div class="flex items-center">
<svg role="button" aria-label="dropdown" tabindex="0" onclick="toggleSubDir(2)" onkeypress="toggleSubDir(2)" class="focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 rounded-md" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.5 3L7.5 6L4.5 9" stroke="#4B5563" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="twitter2" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="twitter2" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Twitter</p>
</div>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">3,521</p>
</div>
<div id="sublist2" class="pl-8 pt-5 hidden">
<div class="flex items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="usa2" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="usa2" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">USA</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div class="flex pt-4 items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="ger2" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="ger2" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Germany</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div class="flex pt-4 items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="italy2" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="italy2" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Italy</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
</div>
</div>
<div>
<div class="flex items-center justify-between mt-4">
<div class="flex items-center">
<svg role="button" aria-label="dropdown" tabindex="0" onclick="toggleSubDir(3)" onkeypress="toggleSubDir(3)" class="focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 rounded-md" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.5 3L7.5 6L4.5 9" stroke="#4B5563" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" />
</svg>
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="insta3" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="insta3" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Instagram</p>
</div>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">5,142</p>
</div>
<div id="sublist3" class="pl-8 pt-5">
<div class="flex items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="usa3" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="usa3" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">USA</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div class="flex pt-4 items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="germany3" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="germany3" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Germany</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
<div class="flex pt-4 items-center justify-between">
<div class="pl-4 flex items-center">
<div class="bg-gray-100 dark:bg-gray-800 border rounded-sm border-gray-200 dark:border-gray-700 w-3 h-3 flex flex-shrink-0 justify-center items-center relative">
<input aria-labelledby="italy3" type="checkbox" class="focus:opacity-100 checkbox opacity-0 absolute cursor-pointer w-full h-full" />
<div class="check-icon hidden bg-indigo-700 text-white rounded-sm">
<svg class="icon icon-tabler icon-tabler-check" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
</div>
</div>
<p id="italy3" tabindex="0" class="focus:outline-none text-sm leading-normal ml-2 text-gray-800">Italy</p>
</div>
<p tabindex="0" class="focus:outline-none w-8 text-xs leading-3 text-right text-indigo-700">2,381</p>
</div>
</div>
</div>
<button class="focus:ring-2 focus:ring-offset-2 focus:ring-indigo-700 focus:outline-none focus:bg-indigo-200 text-xs bg-indigo-100 hover:bg-indigo-200 rounded-md mt-6 font-medium py-2 w-full leading-3 text-indigo-700">Select</button>
</div>
</div>
<style>.checkbox:checked + .check-icon {
display: flex;
}
</style>
<script>let dropdown = document.getElementById("dropdown");
let open1 = document.getElementById("open");
let close1 = document.getElementById("close");
let flag = false;
const dropdownHandler = () => {
if (!flag) {
dropdown.classList.add("hidden");
open1.classList.add("hidden");
close1.classList.remove("hidden");
flag = true;
} else {
dropdown.classList.remove("hidden");
close1.classList.add("hidden");
open1.classList.remove("hidden");
flag = false;
}
};
const toggleSubDir = (check) => {
let subList1 = document.getElementById("sublist1");
let subList2 = document.getElementById("sublist2");
let subList3 = document.getElementById("sublist3");
switch (check) {
case 1:
subList3.classList.add("hidden");
subList2.classList.add("hidden");
subList1.classList.remove("hidden");
break;
case 2:
subList3.classList.add("hidden");
subList2.classList.remove("hidden");
subList1.classList.add("hidden");
break;
case 3:
subList3.classList.remove("hidden");
subList2.classList.add("hidden");
subList1.classList.add("hidden");
break;
}
};
</script>
How to make a Free Tailwind CSS Dropdown Component with Tailwind CSS?
Install tailwind css of verion 2.2.19
Use the script
html tag to import the script of Tailwind CSS of the version 2.2.19
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to make a Free Tailwind CSS Dropdown Component component
focus:bg-gray-100
w-64
p-4
bg-white
text-sm
text-gray-800
flex
hidden
mt-2
pl-4
bg-gray-100
dark:bg-gray-800
border-gray-200
dark:border-gray-700
w-3
h-3
flex-shrink-0
relative
absolute
w-full
h-full
bg-indigo-700
text-white
ml-2
w-8
text-xs
text-right
text-indigo-700
pl-8
pt-5
pt-4
mt-4
focus:bg-indigo-200
bg-indigo-100
hover:bg-indigo-200
mt-6
py-2
37 steps to make a Free Tailwind CSS Dropdown Component component with Tailwind CSS
Control the background color of an element to gray-100 using the
focus:bg-gray-100
utilities on focus.Use
w-64
to set an element to a fixed width(16rem).Control the padding on all sides of an element to 1rem using the
p-4
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the text color of an element to gray-800 using the
text-gray-800
utilities.Use
flex
to create a block-level flex container.Use
hidden
to set an element to display: none and remove it from the page layout.Control the margin on top side of an element to 0.5rem using the
mt-2
utilities.Adjust the left padding of an element to 1rem using the
pl-4
utilities classControl the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the background color of an element to gray-800 using the
dark:bg-gray-800
utilities in dark theme.Control the border color of an element to gray-200 using the
border-gray-200
utilities.Control the border color of an element to gray-700 using the
dark:border-gray-700
utilities in dark theme.Use
w-3
to set an element to a fixed width(0.75rem).Use
h-3
to set an element to a fixed height(0.75rem).Use
flex
to create a block-level flex container.Use
relative
to position an element according to the normal flow of the document.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.Use
w-full
to set an element to a 100% based width.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.Control the background color of an element to indigo-700 using the
bg-indigo-700
utilities.Control the text color of an element to white using the
text-white
utilities.Control the margin on left side of an element to 0.5rem using the
ml-2
utilities.Use
w-8
to set an element to a fixed width(2rem).Control the text color of an element to xs using the
text-xs
utilities.Control the text color of an element to right using the
text-right
utilities.Control the text color of an element to indigo-700 using the
text-indigo-700
utilities.Adjust the left padding of an element to 2rem using the
pl-8
utilities classControl the padding on top side of an element to 1.25rem using the
pt-5
utilities.Control the padding on top side of an element to 1rem using the
pt-4
utilities.Control the margin on top side of an element to 1rem using the
mt-4
utilities.Control the background color of an element to indigo-200 using the
focus:bg-indigo-200
utilities on focus.Control the background color of an element to indigo-100 using the
bg-indigo-100
utilities.Control the background color of an element to indigo-200 using the
hover:bg-indigo-200
utilities on hover.Control the margin on top side of an element to 1.5rem using the
mt-6
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Free Tailwind CSS Dropdown Component components, learn and follow along to implement your own components.