UI elements examples with Tailwind CSS 🖼️

ui-elements-examples-with-tailwind-css-️

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.


  class="
    px-2
    py-1.5
    rounded-md
    bg-blue-500
    hover:bg-blue-600
    font-medium
    text-white
  "
>
  Submit

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.


  class="
    block
    w-48
    p-2
    rounded-md
    bg-slate-200
    font-medium
    text-slate-700
  "
>
   value="apple">Apple
   value="banana">Banana
   value="orange">Orange

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.

 class="flex items-center">
   class="mr-1.5 accent-blue-500" type="checkbox" />
   class="text-slate-800">Subscribe

You can change checkbox background by changing accent-* class.

Form

A boilerplate for a simple and responsive sign up form.

 class="max-w-md p-4 rounded-md border border-slate-100 shadow-md">
  

class="mb-1 font-bold text-xl text-slate-800">Sign up

class="mb-2 text-slate-500"> Create an account and join our awesome community. It's completely free.

class="block mb-2"> class="block mb-1 font-semibold text-sm text-slate-700"> Email address class=" block w-full px-2 py-1.5 rounded ring-1 ring-slate-700/20 text-slate-700 block " type="email" placeholder="Your email" /> class="block mb-3"> class="block mb-1 font-semibold text-sm text-slate-700"> Password class=" block w-full px-2 py-1.5 rounded ring-1 ring-slate-700/20 text-slate-700 block " type="password" placeholder="At least 6 characters" /> class=" w-full mb-1 px-2 py-1.5 rounded-md bg-blue-500 hover:bg-blue-600 font-medium text-white " type="submit" > Register class="block text-xs text-blue-500 hover:text-blue-600 text-center" href="#" > Already have an account?

A boilerplate for a simple modal with close button.


  class="
    fixed
    top-0
    left-0
    p-4
    w-full
    h-full
    bg-slate-800/80
    flex
    items-center
    justify-center
  "
  open
>
   class="max-w-md w-full p-5 rounded-md bg-white shadow-sm">
     class="mb-1 flex items-center justify-between">
      

class="font-bold text-xl text-slate-800"> Lorem ipsum dolor sit amet

class=" shrink-0 w-[1.5rem] h-[1.5rem] rounded bg-slate-100 hover:bg-slate-200 text-slate-600 " > ×
class="leading-relaxed text-slate-500"> Lorem ipsum dolor sit amet consectetur adipisicing elit. Non dolorem vitae optio fuga itaque ab, voluptatibus officia iusto ipsa at.

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! 👋

Total
0
Shares
1 comment
  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
supercharge-your-stepfunctions-productivity-with-local-file-system-sync-in-workflow-studio

Supercharge your StepFunctions productivity with local file system sync in Workflow Studio

Next Post
openbsd-disk-encryption:-change-passphrase

OpenBSD Disk Encryption: Change passphrase

Related Posts
arkui-x平台差异化

ArkUI-X平台差异化

跨平台使用场景是一套ArkTS代码运行在多个终端设备上,如Android、iOS、OpenHarmony(含基于OpenHarmony发行的商业版,如HarmonyOS Next)。当不同平台业务逻辑不同,或使用了不支持跨平台的API,就需要根据平台不同进行一定代码差异化适配。当前仅支持在代码运行态进行差异化,接下来详细介绍场景及如何差异化适配。 使用场景 平台差异化适用于以下两种典型场景: 1.自身业务逻辑不同平台本来就有差异; 2.在OpenHarmony上调用了不支持跨平台的API,这就需要在OpenHarmony上仍然调用对应API,其他平台通过Bridge桥接机制进行差异化处理; 判断平台类型 可以通过let osName: string = deviceInfo.osFullName;获取对应OS名字,该接口已支持跨平台,不同平台上其返回值如下: OpenHarmony上,osName等于OpenHarmony-XXX Android上,osName等于Android XXX iOS上,osName等于iOS XXX 示例如下:…
Read More