Published on

How To Make A Simple Badges With Tailwind CSS From Scratch

Tags
Simple Badges

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

  1. Control the text color of an element to center using the text-center utilities.

  2. Control the text color of an element to 4xl using the text-4xl utilities.

  3. Control the text color of an element to gray-800 using the text-gray-800 utilities.

  4. Control the horizontal margin of an element to auto using the mx-auto utilities.

  5. Control the vertical margin of an element to 2.5rem using the my-10 utilities.

  6. Control the horizontal padding of an element to 1rem using the px-4 utilities.

  7. Use flex to create a block-level flex container.

  8. Use flex to create a block-level flex container.

  9. Use grid to create a grid container.

  10. Use grid to create a grid container.

  11. Use w-full to set an element to a 100% based width.

  12. To specify the width between columns, you can use the gap-4 utilities.

  13. Control the background color of an element to white using the bg-white utilities.

  14. Control the padding on all sides of an element to 1.5rem using the p-6 utilities.

  15. Control the border color of an element to gray-500 using the border-gray-500 utilities.

  16. Control the margin on bottom side of an element to 2rem using the mb-8 utilities.

  17. Control the text color of an element to left using the text-left utilities.

  18. Control the text color of an element to gray-700 using the text-gray-700 utilities.

  19. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent.

  20. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  21. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

  22. Control the horizontal padding of an element to 0.5rem using the px-2 utilities.

  23. Control the vertical padding of an element to 0.25rem using the py-1 utilities.

  24. Control the text color of an element to xs using the text-xs utilities.

  25. Control the margin on right side of an element to 0.75rem using the mr-3 utilities.

  26. Control the text color of an element to white using the text-white utilities.

  27. Control the background color of an element to purple-500 using the bg-purple-500 utilities.

  28. Control the background color of an element to indigo-500 using the bg-indigo-500 utilities.

  29. Control the background color of an element to blue-500 using the bg-blue-500 utilities.

  30. Control the background color of an element to yellow-500 using the bg-yellow-500 utilities.

  31. Control the background color of an element to red-500 using the bg-red-500 utilities.

  32. Control the border color of an element to 1rem using the border-4 utilities.

  33. Control the border color of an element to gray-400 using the border-gray-400 utilities.

  34. Control the padding on all sides of an element to 0.25rem using the p-1 utilities.

  35. Control the border color of an element to purple-400 using the border-purple-400 utilities.

  36. Control the border color of an element to indigo-400 using the border-indigo-400 utilities.

  37. Control the border color of an element to blue-400 using the border-blue-400 utilities.

  38. Control the border color of an element to yellow-400 using the border-yellow-400 utilities.

  39. Control the border color of an element to red-400 using the border-red-400 utilities.

  40. Use relative to position an element according to the normal flow of the document.

  41. Use float-left to float an element to the left of its container.

  42. Control the margin on right side of an element to 0.5rem using the mr-2 utilities.

  43. Use w-16 to set an element to a fixed width(4rem).

  44. Use h-16 to set an element to a fixed height(4rem).

  45. Use the top-0 utilities to set the top position of a positioned element to 0rem.

  46. 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.

  47. Use w-5 to set an element to a fixed width(1.25rem).

  48. Use h-5 to set an element to a fixed height(1.25rem).

  49. Use the bottom-0 utilities to set the bottom position of a positioned element to 0rem.

  50. Use the left-0 utilities to set the left position of a positioned element to 0rem.

  51. 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.