Table of contents
- Introduction
- What is Tailwind CSS?
-
Examples
- Button
- Input
- Select
- Checkbox
- Form
- Modal
- Summary
Introduction
In this article I would like to go over the basics of using Tailwind CSS and provide some examples on how you can use it to create common UI elements such as buttons, forms, modals, navigation menus and so on, so you can later reuse them in your own projects.
What is Tailwind CSS?
In case you’re not familiar with it already, Tailwind CSS is a utility-first CSS framework that allows you to create custom user interfaces without the bloat of traditional frameworks. It’s perfect to quickly prototype and build beautiful, functional user interfaces for your web projects. You can read more about it on their website here.
Examples
Let’s dive in and take a look at how we can use Tailwind CSS to create some common UI elements. Each example comes with a ready to use HTML code snippet.
Button
A base for a regular primary button.
You can change bg-*
and text-*
classes to create other variants:
- red –
bg-red-500 hover:bg-red-600 text-white
- dark –
bg-slate-900 hover:bg-slate-800 text-white
- light –
bg-slate-50 hover:bg-slate-100 text-slate-800
Input
A base for a regular input field.
class="
px-2
py-1.5
rounded
ring-1 ring-slate-700/20
text-slate-700
block
"
type="email"
placeholder="Your email goes here"
/>
You can change ring-*
class to create other variants:
- blue –
ring-blue-500/30
- red –
ring-red-500/30
Select
A base for a regular select element.
This one has some limitations in terms of styling, but still I prefer to use native solutions rather than building my own from scratch. Just for the sake of accessibility.
Checkbox
A base for a regular checkbox field with label.
You can change checkbox background by changing accent-*
class.
Form
A boilerplate for a simple and responsive sign up form.
Modal
A boilerplate for a simple modal with close button.
All of the above listed examples are also available here, so take a look to see them in action.
Summary
I hope this article provided you with a good demonstration of Tailwind CSS possibilities. If you have a specific questions or examples that you’d like to see, feel free to leave them in the comment section below.
Thanks for reading! 👋
I may need your help. I tried many ways but couldn’t solve it, but after reading your article, I think you have a way to help me. I’m looking forward for your reply. Thanks.