Badges
Badges are small components useful for labeling and providing additional information. We will use them to finish our contact section.
Basic example
Badge is an element for the use of drawing attention to additional interface information with eye-catching appeal, typically displaying unread messages count.
<h2 class="text-4xl font-medium leading-tight">
Example heading
<span
class="inline-block whitespace-nowrap rounded-md bg-primary-100 px-4 py-3 text-center align-top text-lg font-bold leading-none text-primary-700"
>New</span
>
</h2>
Example heading New
The construction is very simple, but let's explain the classes present here one by one:
-
inline-block
: This appliesdisplay: inline-block
to the element. It means the element will be inline, but can have width and height, like a block element. -
whitespace-nowrap
: This applieswhite-space: nowrap
to the element. This prevents the text inside the element from wrapping onto the next line. -
rounded-md
: This applies medium rounded corners to the element. -
bg-primary-100
: This applies a background color to the element. The color applied is defined by theprimary-100
color in your Tailwind CSS configuration. -
px-4
: This applies horizontal padding (left and right) to the element, equivalent to 1rem or 16px. -
py-3
: This applies vertical padding (top and bottom) to the element, equivalent to 0.75rem or 12px. -
text-center
: This centers the text inside the element. -
text-lg
: This applies large text size to the element. -
align-top
: This appliesvertical-align: top
to the element. This would only take effect if the element isinline
orinline-block
. -
font-bold
: This appliesfont-weight: bold
to the element, making the text bold. -
leading-none
: This sets the line-height to 1, meaning the line height will be the same as the font size. -
text-primary-700
: This applies a text color to the element. The color applied is defined by theprimary-700
color in your Tailwind CSS configuration.
Icon inside
We can put an icon in a label very easily:
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
Note that when we use an icon instead of text, we can get rid of many of the previously mentioned text classes.
Now let's add labels to our project.
Step 1 - add text to the badge
In our project we will use a badge with an icon inside, and we will add text next to it. We will put together it in a flexbox.
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">Press</p>
<p class="text-gray-600 dark:text-gray-400">press@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+1 234-567-87</p>
</div>
</div>
Press
press@example.com
+1 234-567-87
Thanks to flexbox, we can define how the badge should be aligned in relation to the text.
By default it's aligned to the top. However, if we add
.items-center
or .items-end
class next to the
.flex
, then we can modify the alignment.
<!-- Top aligned -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">Press</p>
<p class="text-gray-600 dark:text-gray-400">press@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+1 234-567-87</p>
</div>
</div>
<!-- Top aligned -->
<!-- Centered -->
<div class="flex items-center">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">Press</p>
<p class="text-gray-600 dark:text-gray-400">press@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+1 234-567-87</p>
</div>
</div>
<!-- Centered -->
<!-- Bottom aligned -->
<div class="flex items-end">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">Press</p>
<p class="text-gray-600 dark:text-gray-400">press@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+1 234-567-87</p>
</div>
</div>
<!-- Bottom aligned -->
Press
press@example.com
+1 234-567-87
Press
press@example.com
+1 234-567-87
Press
press@example.com
+1 234-567-87
Step 2 - create 4 badges within a grid
Let's create 4 badges for our contact form and place them in the grid, two columns in a row.
<div class="grid gap-12 lg:grid-cols-2">
<!-- Press -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">Press</p>
<p class="text-gray-600 dark:text-gray-400">press@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+1 654-234-65</p>
</div>
</div>
<!-- Press -->
<!-- Sales questions -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 6v12m-3-2.818l.879.659c1.171.879 3.07.879 4.242 0 1.172-.879 1.172-2.303 0-3.182C13.536 12.219 12.768 12 12 12c-.725 0-1.45-.22-2.003-.659-1.106-.879-1.106-2.303 0-3.182s2.9-.879 4.006 0l.415.33M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Sales questions
</p>
<p class="text-gray-600 dark:text-gray-400">sales@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+2 875-345-73</p>
</div>
</div>
<!-- Sales questions -->
<!-- Technical support -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 002.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 01-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 00-1.091-.852H4.5A2.25 2.25 0 002.25 4.5v2.25z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Technical support
</p>
<p class="text-gray-600 dark:text-gray-400">support@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+1 234-567-87</p>
</div>
</div>
<!-- Technical support -->
<!-- Bug report -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0112 12.75zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 01-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 002.248-2.354M12 12.75a2.25 2.25 0 01-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 00-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 01.4-2.253M12 8.25a2.25 2.25 0 00-2.248 2.146M12 8.25a2.25 2.25 0 012.248 2.146M8.683 5a6.032 6.032 0 01-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0115.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 00-.575-1.752M4.921 6a24.048 24.048 0 00-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 01-5.223 1.082" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Bug report
</p>
<p class="text-gray-600 dark:text-gray-400">bugs@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+3 735-325-44</p>
</div>
</div>
<!-- Bug report -->
</div>
Press
press@example.com
+1 654-234-65
Sales questions
sales@example.com
+2 875-345-73
Technical support
support@example.com
+1 234-567-87
Bug report
bugs@example.com
+3 735-325-44
Step 3 - add badges to the Contact section
Now let's add our badges to the second column in the Contact Section.
<!-- Section: Contact -->
<section class="mb-28">
<h3
class="mb-10 text-center text-3xl font-semibold text-gray-700 dark:text-white">
Contact us
</h3>
<div class="grid gap-12 lg:grid-cols-12">
<!-- First column -->
<div class="lg:col-span-5">[...]</div>
<!-- First column -->
<!-- Second column -->
<div class="lg:col-span-7">
<div class="grid gap-12 lg:grid-cols-2">
<!-- Press -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Press
</p>
<p class="text-gray-600 dark:text-gray-400">
press@example.com
</p>
<p class="text-gray-600 dark:text-gray-400">+1 654-234-65</p>
</div>
</div>
<!-- Press -->
<!-- Sales questions -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 6v12m-3-2.818l.879.659c1.171.879 3.07.879 4.242 0 1.172-.879 1.172-2.303 0-3.182C13.536 12.219 12.768 12 12 12c-.725 0-1.45-.22-2.003-.659-1.106-.879-1.106-2.303 0-3.182s2.9-.879 4.006 0l.415.33M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Sales questions
</p>
<p class="text-gray-600 dark:text-gray-400">
sales@example.com
</p>
<p class="text-gray-600 dark:text-gray-400">+2 875-345-73</p>
</div>
</div>
<!-- Sales questions -->
<!-- Technical support -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 002.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 01-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 00-1.091-.852H4.5A2.25 2.25 0 002.25 4.5v2.25z" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Technical support
</p>
<p class="text-gray-600 dark:text-gray-400">
support@example.com
</p>
<p class="text-gray-600 dark:text-gray-400">+1 234-567-87</p>
</div>
</div>
<!-- Technical support -->
<!-- Bug report -->
<div class="flex">
<!-- Badge -->
<div>
<span
class="me-4 inline-block rounded-lg bg-primary-100 p-4 text-primary-700">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0112 12.75zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 01-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 002.248-2.354M12 12.75a2.25 2.25 0 01-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 00-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 01.4-2.253M12 8.25a2.25 2.25 0 00-2.248 2.146M12 8.25a2.25 2.25 0 012.248 2.146M8.683 5a6.032 6.032 0 01-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0115.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 00-.575-1.752M4.921 6a24.048 24.048 0 00-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 01-5.223 1.082" />
</svg>
</span>
</div>
<!-- Text -->
<div>
<p class="mb-2 font-semibold text-gray-700 dark:text-white">
Bug report
</p>
<p class="text-gray-600 dark:text-gray-400">bugs@example.com</p>
<p class="text-gray-600 dark:text-gray-400">+3 735-325-44</p>
</div>
</div>
<!-- Bug report -->
</div>
</div>
<!-- Second column -->
</div>
</section>
<!-- Section: Contact -->
And this is what it should look like in the end:
About author
Michal Szymanski
Co Founder at TW Elements and MDBootstrap / Listed in Forbes „30 under 30" / Open-source enthusiast / Dancer, nerd & book lover.
Author of hundreds of articles on programming, business, marketing and productivity. In the past, an educator working with troubled youth in orphanages and correctional facilities.