- Published on
How To Make A Example Chat With Tailwind CSS From Scratch

- What is Tailwind CSS?
- The description of Example Chat ui component
- Why use Tailwind CSS to make a Example Chat ui component?
- The preview of Example Chat ui component
- The source code of Example Chat ui component
- How to make a Example Chat with Tailwind CSS?
- Install tailwind css of verion 2.0.3
- All the unility class needed to make a Example Chat component
- 56 steps to make a Example Chat 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 Example Chat ui component
This is example chat
Why use Tailwind CSS to make a Example Chat ui component?
- It can make the building process of Example Chat ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Example Chat component file.
The preview of Example Chat ui component
Free download of the Example Chat's source code
The source code of Example Chat ui component
<!-- This is an example component -->
<div class="w-screen">
<div class="grid grid-cols-3 min-w-full border rounded" style="min-height: 80vh;">
<div class="col-span-1 bg-white border-r border-gray-300">
<div class="my-3 mx-3 ">
<div class="relative text-gray-600 focus-within:text-gray-400">
<span class="absolute inset-y-0 left-0 flex items-center pl-2">
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" class="w-6 h-6 text-gray-500"><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
</span>
<input aria-placeholder="Busca tus amigos o contacta nuevos" placeholder="Busca tus amigos"
class="py-2 pl-10 block w-full rounded bg-gray-100 outline-none focus:text-gray-700" type="search" name="search" required autocomplete="search" />
</div>
</div>
<ul class="overflow-auto" style="height: 500px;">
<h2 class="ml-2 mb-2 text-gray-600 text-lg my-2">Chats</h2>
<li>
<a class="hover:bg-gray-100 border-b border-gray-300 px-3 py-2 cursor-pointer flex items-center text-sm focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
<img class="h-10 w-10 rounded-full object-cover"
src="https://images.pexels.com/photos/837358/pexels-photo-837358.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
alt="username" />
<div class="w-full pb-2">
<div class="flex justify-between">
<span class="block ml-2 font-semibold text-base text-gray-600 ">Jhon C</span>
<span class="block ml-2 text-sm text-gray-600">5 minutes</span>
</div>
<span class="block ml-2 text-sm text-gray-600">Hello world!!</span>
</div>
</a>
<a class="bg-gray-100 border-b border-gray-300 px-3 py-2 cursor-pointer flex items-center text-sm focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
<img class="h-10 w-10 rounded-full object-cover"
src="https://images.pexels.com/photos/3777931/pexels-photo-3777931.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
alt="username" />
<div class="w-full pb-2">
<div class="flex justify-between">
<span class="block ml-2 font-semibold text-base text-gray-600 ">Eduard</span>
<span class="block ml-2 text-sm text-gray-600">15 minutes</span>
</div>
<span class="block ml-2 text-sm text-gray-600">I am fine</span>
</div>
</a>
<a class="hover:bg-gray-100 border-b border-gray-300 px-3 py-2 cursor-pointer flex items-center text-sm focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
<img class="h-10 w-10 rounded-full object-cover"
src="https://images.pexels.com/photos/6238133/pexels-photo-6238133.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
alt="username" />
<div class="w-full pb-2">
<div class="flex justify-between">
<span class="block ml-2 font-semibold text-base text-gray-600 ">Celia</span>
<span class="block ml-2 text-sm text-gray-600">1 hour</span>
</div>
<span class="block ml-2 text-sm text-gray-600">Last message</span>
</div>
</a>
</li>
</ul>
</div>
<div class="col-span-2 bg-white">
<div class="w-full">
<div class="flex items-center border-b border-gray-300 pl-3 py-3">
<img class="h-10 w-10 rounded-full object-cover"
src="https://images.pexels.com/photos/3777931/pexels-photo-3777931.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
alt="username" />
<span class="block ml-2 font-bold text-base text-gray-600">Eduard</span>
<span class="connected text-green-500 ml-2" >
<svg width="6" height="6">
<circle cx="3" cy="3" r="3" fill="currentColor"></circle>
</svg>
</span>
</div>
<div id="chat" class="w-full overflow-y-auto p-10 relative" style="height: 700px;" ref="toolbarChat">
<ul>
<li class="clearfix2">
<div class="w-full flex justify-start">
<div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
<span class="block">Hello bro</span>
<span class="block text-xs text-right">10:30pm</span>
</div>
</div>
<div class="w-full flex justify-end" >
<div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
<span class="block">Hello</span>
<span class="block text-xs text-left">10:32pm</span>
</div>
</div>
<div class="w-full flex justify-end" >
<div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
<span class="block">how are you?</span>
<span class="block text-xs text-left">10:32pm</span>
</div>
</div>
<div class="w-full flex justify-start">
<div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
<span class="block">I am fine</span>
<span class="block text-xs text-right">10:42pm</span>
</div>
</div>
</li>
</ul>
</div>
<div class="w-full py-3 px-3 flex items-center justify-between border-t border-gray-300">
<button class="outline-none focus:outline-none">
<svg class="text-gray-400 h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
</button>
<button class="outline-none focus:outline-none ml-1">
<svg class="text-gray-400 h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" />
</svg>
</button>
<input aria-placeholder="Escribe un mensaje aquí" placeholder="Escribe un mensaje aquí"
class="py-2 mx-3 pl-5 block w-full rounded-full bg-gray-100 outline-none focus:text-gray-700" type="text" name="message" required/>
<button class="outline-none focus:outline-none" type="submit">
<svg class="text-gray-400 h-7 w-7 origin-center transform rotate-90" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z" />
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
How to make a Example Chat with Tailwind CSS?
Install tailwind css of verion 2.0.3
Use the script
html tag to import the script of Tailwind CSS of the version 2.0.3
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to make a Example Chat component
w-screen
grid
grid-cols-3
min-w-full
bg-white
border-r
border-gray-300
my-3
mx-3
relative
text-gray-600
focus-within:text-gray-400
absolute
left-0
flex
pl-2
w-6
h-6
text-gray-500
py-2
pl-10
block
w-full
bg-gray-100
focus:text-gray-700
overflow-auto
ml-2
mb-2
text-lg
my-2
hover:bg-gray-100
border-b
px-3
text-sm
focus:border-gray-300
h-10
w-10
pb-2
text-base
pl-3
py-3
text-green-500
overflow-y-auto
p-10
justify-start
px-5
text-gray-700
text-xs
text-right
text-left
border-t
text-gray-400
ml-1
pl-5
h-7
w-7
56 steps to make a Example Chat component with Tailwind CSS
Use
w-screen
to make an element span the entire width of the viewport.Use
grid
to create a grid container.Use
grid
to create a grid container.Set the minimum width/height of an element using the
min-w-full
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the border color of an element to r using the
border-r
utilities.Control the border color of an element to gray-300 using the
border-gray-300
utilities.Control the vertical margin of an element to 0.75rem using the
my-3
utilities.Control the horizontal margin of an element to 0.75rem using the
mx-3
utilities.Use
relative
to position an element according to the normal flow of the document.Control the text color of an element to gray-600 using the
text-gray-600
utilities.Control the text color of an element to gray-400undefined using the
focus-within:text-gray-400
utilities.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 the
left-0
utilities to set the left position of a positioned element to 0rem.Use
flex
to create a block-level flex container.Set the left padding of the element to 0.5rem using the
pl-2
utilities classUse
w-6
to set an element to a fixed width(1.5rem).Use
h-6
to set an element to a fixed height(1.5rem).Control the text color of an element to gray-500 using the
text-gray-500
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Set the left padding of the element to 2.5rem using the
pl-10
utilities classUse
inline
utilities to put the element on its own line and fill its parent.Use
w-full
to set an element to a 100% based width.Control the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the text color of an element to gray-700 on focus using the
focus:text-gray-700
utilities.Use
overflow-auto
to add scrollbars to an element in the event that its content overflows the bounds of that element. Unlike.overflow-scroll
, which always shows scrollbars, this utility will only show them if scrolling is necessary.Control the margin on left side of an element to 0.5rem using the
ml-2
utilities.Control the margin on bottom side of an element to 0.5rem using the
mb-2
utilities.Control the text color of an element to lg using the
text-lg
utilities.Control the vertical margin of an element to 0.5rem using the
my-2
utilities.Control the background color of an element to gray-100 using the
hover:bg-gray-100
utilities on hover.Control the border color of an element to b using the
border-b
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the border color of an element to gray-300 using the
focus:border-gray-300
utilities on focus.Use
h-10
to set an element to a fixed height(2.5rem).Use
w-10
to set an element to a fixed width(2.5rem).Control the padding on bottom side of an element to 0.5rem using the
pb-2
utilities.Control the text color of an element to base using the
text-base
utilities.Set the left padding of the element to 0.75rem using the
pl-3
utilities classControl the vertical padding of an element to 0.75rem using the
py-3
utilities.Control the text color of an element to green-500 using the
text-green-500
utilities.Use
overflow-y-auto
to allow vertical scrolling if needed.Control the padding on all sides of an element to 2.5rem using the
p-10
utilities.Use
justify-start
to justify items against the start of the container’s main axis.Control the horizontal padding of an element to 1.25rem using the
px-5
utilities.Control the text color of an element to gray-700 using the
text-gray-700
utilities.Control the text color of an element to xs using the
text-xs
utilities.Control the text color of an element to right using the
text-right
utilities.Control the text color of an element to left using the
text-left
utilities.Control the border color of an element to t using the
border-t
utilities.Control the text color of an element to gray-400 using the
text-gray-400
utilities.Control the margin on left side of an element to 0.25rem using the
ml-1
utilities.Set the left padding of the element to 1.25rem using the
pl-5
utilities classUse
h-7
to set an element to a fixed height(1.75rem).Use
w-7
to set an element to a fixed width(1.75rem).
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Example Chat components, learn and follow along to implement your own components.