- Published on
How To Make A Simple Badges With Tailwind CSS From Scratch

- What is Tailwind CSS?
- The description of Simple Badges ui component
- Why use Tailwind CSS to make a Simple Badges ui component?
- The preview of Simple Badges ui component
- The source code of Simple Badges ui component
- How to make a Simple Badges with Tailwind CSS?
- Install tailwind css of verion 1.4.6
- All the unility class needed to make a Simple Badges component
- 51 steps to make a Simple Badges 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 Simple Badges ui component
Example of some badges
Why use Tailwind CSS to make a Simple Badges ui component?
- It can make the building process of Simple Badges ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Simple Badges component file.
The preview of Simple Badges ui component
Free download of the Simple Badges's source code
The source code of Simple Badges ui component
<header>
<div class="text-center text-4xl text-gray-800 font-bold mx-auto my-10">
Simple Badges
</div>
</header>
<main class="px-4 flex-grow flex justify-center items-center text-center container mx-auto grid row-gap-4 grid-cols-1 w-full">
<div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">
<div class="mb-8 text-left">
<h2 class="text-gray-700">Badges</h2>
</div>
<div class="text-left">
<span class="inline-block rounded-min text-gray-600 bg-gray-100 px-2 py-1 text-xs font-bold mr-3">Default</span>
<span class="inline-block rounded-min text-white bg-purple-500 px-2 py-1 text-xs font-bold mr-3">Primary</span>
<span class="inline-block rounded-min text-white bg-indigo-500 px-2 py-1 text-xs font-bold mr-3">Success</span>
<span class="inline-block rounded-min text-white bg-blue-500 px-2 py-1 text-xs font-bold mr-3">Info</span>
<span class="inline-block rounded-min text-white bg-yellow-500 px-2 py-1 text-xs font-bold mr-3">Warning</span>
<span class="inline-block rounded-min text-white bg-red-500 px-2 py-1 text-xs font-bold mr-3">Danger</span>
</div>
</div>
<div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">
<div class="mb-8 text-left">
<h2 class="text-gray-700">Pill</h2>
</div>
<div class="text-left">
<span class="inline-block rounded-full text-gray-600 bg-gray-100 px-2 py-1 text-xs font-bold mr-3">Default</span>
<span class="inline-block rounded-full text-white bg-purple-500 px-2 py-1 text-xs font-bold mr-3">Primary</span>
<span class="inline-block rounded-full text-white bg-indigo-500 px-2 py-1 text-xs font-bold mr-3">Success</span>
<span class="inline-block rounded-full text-white bg-blue-500 px-2 py-1 text-xs font-bold mr-3">Info</span>
<span class="inline-block rounded-full text-white bg-yellow-500 px-2 py-1 text-xs font-bold mr-3">Warning</span>
<span class="inline-block rounded-full text-white bg-red-500 px-2 py-1 text-xs font-bold mr-3">Danger</span>
</div>
</div>
<div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">
<div class="mb-8 text-left">
<h2 class="text-gray-700">Links</h2>
</div>
<div class="text-left">
<a href="#" class="inline-block rounded-full text-gray-600 bg-gray-100 px-2 py-1 text-xs font-bold mr-3">Default</a>
<a href="#" class="inline-block rounded-full text-white bg-purple-500 px-2 py-1 text-xs font-bold mr-3">Primary</a>
<a href="#" class="inline-block rounded-full text-white bg-indigo-500 px-2 py-1 text-xs font-bold mr-3">Success</a>
<a href="#" class="inline-block rounded-full text-white bg-blue-500 px-2 py-1 text-xs font-bold mr-3">Info</a>
<a href="#" class="inline-block rounded-full text-white bg-yellow-500 px-2 py-1 text-xs font-bold mr-3">Warning</a>
<a href="#" class="inline-block rounded-full text-white bg-red-500 px-2 py-1 text-xs font-bold mr-3">Danger</a>
</div>
</div>
<div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">
<div class="mb-8 text-left">
<h2 class="text-gray-700">Status Badge</h2>
</div>
<div class="text-left">
<span href="#" class="inline-block rounded-full bg-white border-4 border-gray-400 p-1 text-xs font-bold mr-3"></span>
<span href="#" class="inline-block rounded-full bg-white border-4 border-purple-400 p-1 text-xs font-bold mr-3"></span>
<span href="#" class="inline-block rounded-full bg-white border-4 border-indigo-400 p-1 text-xs font-bold mr-3"></span>
<span href="#" class="inline-block rounded-full bg-white border-4 border-blue-400 p-1 text-xs font-bold mr-3"></span>
<span href="#" class="inline-block rounded-full bg-white border-4 border-yellow-400 p-1 text-xs font-bold mr-3"></span>
<span href="#" class="inline-block rounded-full bg-white border-4 border-red-400 p-1 text-xs font-bold mr-3"></span>
</div>
</div>
<div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">
<div class="mb-8 text-left">
<h2 class="text-gray-700">List Media Status</h2>
</div>
<ul class="inline-block">
<li>
<div class="relative float-left mr-2 flex">
<img src="https://images.unsplash.com/photo-1499996860823-5214fcc65f8f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1404&q=80" alt="" class="rounded-full w-16 h-16 object-cover">
<div class="top-0 absolute rounded-full w-5 h-5 bg-white inline-block flex justify-center items-center">
<span href="#" class="inline-block rounded-full bg-white border-4 border-red-400 p-1 text-xs"></span>
</div>
</div>
</li>
<li>
<div class="relative float-left mr-2 flex">
<img src="https://images.unsplash.com/photo-1499996860823-5214fcc65f8f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1404&q=80" alt="" class="rounded-full w-16 h-16 object-cover">
<div class="bottom-0 absolute rounded-full w-5 h-5 bg-white inline-block flex justify-center items-center">
<span href="#" class="inline-block rounded-full bg-white border-4 border-yellow-400 p-1 text-xs"></span>
</div>
</div>
</li>
<li>
<div class="relative float-left mr-2 flex">
<img src="https://images.unsplash.com/photo-1499996860823-5214fcc65f8f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1404&q=80" alt="" class="rounded-full w-16 h-16 object-cover">
<div class="left-0 absolute rounded-full w-5 h-5 bg-white inline-block flex justify-center items-center">
<span href="#" class="inline-block rounded-full bg-white border-4 border-blue-400 p-1 text-xs"></span>
</div>
</div>
</li>
<li>
<div class="relative float-left mr-2 flex">
<img src="https://images.unsplash.com/photo-1499996860823-5214fcc65f8f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1404&q=80" alt="" class="rounded-full w-16 h-16 object-cover">
<div class="right-0 absolute rounded-full w-5 h-5 bg-white inline-block flex justify-center items-center">
<span href="#" class="inline-block rounded-full bg-white border-4 border-purple-400 p-1 text-xs"></span>
</div>
</div>
</li>
</ul>
</div>
</main>
How to make a Simple Badges with Tailwind CSS?
Install tailwind css of verion 1.4.6
Use the link
html tag to import the stylesheet of Tailwind CSS of the version 1.4.6
<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">
All the unility class needed to make a Simple Badges component
text-center
text-4xl
text-gray-800
mx-auto
my-10
px-4
flex-grow
flex
grid
grid-cols-1
w-full
gap-4
bg-white
p-6
border-gray-500
mb-8
text-left
text-gray-700
inline-block
text-gray-600
bg-gray-100
px-2
py-1
text-xs
mr-3
text-white
bg-purple-500
bg-indigo-500
bg-blue-500
bg-yellow-500
bg-red-500
border-4
border-gray-400
p-1
border-purple-400
border-indigo-400
border-blue-400
border-yellow-400
border-red-400
relative
float-left
mr-2
w-16
h-16
top-0
absolute
w-5
h-5
bottom-0
left-0
right-0
51 steps to make a Simple Badges component with Tailwind CSS
Control the text color of an element to center using the
text-center
utilities.Control the text color of an element to 4xl using the
text-4xl
utilities.Control the text color of an element to gray-800 using the
text-gray-800
utilities.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Control the vertical margin of an element to 2.5rem using the
my-10
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Use
grid
to create a grid container.Use
grid
to create a grid container.Use
w-full
to set an element to a 100% based width.To specify the width between columns, you can use the
gap-4
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 1.5rem using the
p-6
utilities.Control the border color of an element to gray-500 using the
border-gray-500
utilities.Control the margin on bottom side of an element to 2rem using the
mb-8
utilities.Control the text color of an element to left using the
text-left
utilities.Control the text color of an element to gray-700 using the
text-gray-700
utilities.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 gray-600 using the
text-gray-600
utilities.Control the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the horizontal padding of an element to 0.5rem using the
px-2
utilities.Control the vertical padding of an element to 0.25rem using the
py-1
utilities.Control the text color of an element to xs using the
text-xs
utilities.Control the margin on right side of an element to 0.75rem using the
mr-3
utilities.Control the text color of an element to white using the
text-white
utilities.Control the background color of an element to purple-500 using the
bg-purple-500
utilities.Control the background color of an element to indigo-500 using the
bg-indigo-500
utilities.Control the background color of an element to blue-500 using the
bg-blue-500
utilities.Control the background color of an element to yellow-500 using the
bg-yellow-500
utilities.Control the background color of an element to red-500 using the
bg-red-500
utilities.Control the border color of an element to 1rem using the
border-4
utilities.Control the border color of an element to gray-400 using the
border-gray-400
utilities.Control the padding on all sides of an element to 0.25rem using the
p-1
utilities.Control the border color of an element to purple-400 using the
border-purple-400
utilities.Control the border color of an element to indigo-400 using the
border-indigo-400
utilities.Control the border color of an element to blue-400 using the
border-blue-400
utilities.Control the border color of an element to yellow-400 using the
border-yellow-400
utilities.Control the border color of an element to red-400 using the
border-red-400
utilities.Use
relative
to position an element according to the normal flow of the document.Use
float-left
to float an element to the left of its container.Control the margin on right side of an element to 0.5rem using the
mr-2
utilities.Use
w-16
to set an element to a fixed width(4rem).Use
h-16
to set an element to a fixed height(4rem).Use the
top-0
utilities to set the top position of a positioned element to 0rem.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-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 the
bottom-0
utilities to set the bottom position of a positioned element to 0rem.Use the
left-0
utilities to set the left position of a positioned element to 0rem.Use the
right-0
utilities to set the right position of a positioned element to 0rem.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Simple Badges components, learn and follow along to implement your own components.