Published on

Beginners Guide: Make A Chat Messages With Tailwind CSS

Tags
Chat Messages

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 Chat Messages ui component

Design inspiration from dribble.com

Why use Tailwind CSS to build a Chat Messages ui component?

  • It can make the building process of Chat Messages ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Chat Messages component file.

The preview of Chat Messages ui component

Free download of the Chat Messages's source code

The source code of Chat Messages ui component

<!-- This is an example component -->
<div class="container mx-auto shadow-lg rounded-lg">
        <!-- headaer -->
    <div class="px-5 py-5 flex justify-between items-center bg-white border-b-2">
      <div class="font-semibold text-2xl">GoingChat</div>
      <div class="w-1/2">
        <input
          type="text"
          name=""
          id=""
          placeholder="search IRL"
          class="rounded-2xl bg-gray-100 py-3 px-5 w-full"
        />
      </div>
      <div
        class="h-12 w-12 p-2 bg-yellow-500 rounded-full text-white font-semibold flex items-center justify-center"
      >
        RA
      </div>
    </div>
    <!-- end header -->
    <!-- Chatting -->
    <div class="flex flex-row justify-between bg-white">
      <!-- chat list -->
      <div class="flex flex-col w-2/5 border-r-2 overflow-y-auto">
        <!-- search compt -->
        <div class="border-b-2 py-4 px-2">
          <input
            type="text"
            placeholder="search chatting"
            class="py-2 px-2 border-2 border-gray-200 rounded-2xl w-full"
          />
        </div>
        <!-- end search compt -->
        <!-- user list -->
        <div
          class="flex flex-row py-4 px-2 justify-center items-center border-b-2"
        >
          <div class="w-1/4">
            <img
              src="https://source.unsplash.com/_7LbC5J-jw4/600x600"
              class="object-cover h-12 w-12 rounded-full"
              alt=""
            />
          </div>
          <div class="w-full">
            <div class="text-lg font-semibold">Luis1994</div>
            <span class="text-gray-500">Pick me at 9:00 Am</span>
          </div>
        </div>
        <div class="flex flex-row py-4 px-2 items-center border-b-2">
          <div class="w-1/4">
            <img
              src="https://source.unsplash.com/otT2199XwI8/600x600"
              class="object-cover h-12 w-12 rounded-full"
              alt=""
            />
          </div>
          <div class="w-full">
            <div class="text-lg font-semibold">Everest Trip 2021</div>
            <span class="text-gray-500">Hi Sam, Welcome</span>
          </div>
        </div>
        <div
          class="flex flex-row py-4 px-2 items-center border-b-2 border-l-4 border-blue-400"
        >
          <div class="w-1/4">
            <img
              src="https://source.unsplash.com/L2cxSuKWbpo/600x600"
              class="object-cover h-12 w-12 rounded-full"
              alt=""
            />
          </div>
          <div class="w-full">
            <div class="text-lg font-semibold">MERN Stack</div>
            <span class="text-gray-500">Lusi : Thanks Everyone</span>
          </div>
        </div>
        <div class="flex flex-row py-4 px-2 items-center border-b-2">
          <div class="w-1/4">
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-12 w-12 rounded-full"
              alt=""
            />
          </div>
          <div class="w-full">
            <div class="text-lg font-semibold">Javascript Indonesia</div>
            <span class="text-gray-500">Evan : some one can fix this</span>
          </div>
        </div>
        <div class="flex flex-row py-4 px-2 items-center border-b-2">
          <div class="w-1/4">
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-12 w-12 rounded-full"
              alt=""
            />
          </div>
          <div class="w-full">
            <div class="text-lg font-semibold">Javascript Indonesia</div>
            <span class="text-gray-500">Evan : some one can fix this</span>
          </div>
        </div>

        <div class="flex flex-row py-4 px-2 items-center border-b-2">
          <div class="w-1/4">
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-12 w-12 rounded-full"
              alt=""
            />
          </div>
          <div class="w-full">
            <div class="text-lg font-semibold">Javascript Indonesia</div>
            <span class="text-gray-500">Evan : some one can fix this</span>
          </div>
        </div>
        <!-- end user list -->
      </div>
      <!-- end chat list -->
      <!-- message -->
      <div class="w-full px-5 flex flex-col justify-between">
        <div class="flex flex-col mt-5">
          <div class="flex justify-end mb-4">
            <div
              class="mr-2 py-3 px-4 bg-blue-400 rounded-bl-3xl rounded-tl-3xl rounded-tr-xl text-white"
            >
              Welcome to group everyone !
            </div>
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-8 w-8 rounded-full"
              alt=""
            />
          </div>
          <div class="flex justify-start mb-4">
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-8 w-8 rounded-full"
              alt=""
            />
            <div
              class="ml-2 py-3 px-4 bg-gray-400 rounded-br-3xl rounded-tr-3xl rounded-tl-xl text-white"
            >
              Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat
              at praesentium, aut ullam delectus odio error sit rem. Architecto
              nulla doloribus laborum illo rem enim dolor odio saepe,
              consequatur quas?
            </div>
          </div>
          <div class="flex justify-end mb-4">
            <div>
              <div
                class="mr-2 py-3 px-4 bg-blue-400 rounded-bl-3xl rounded-tl-3xl rounded-tr-xl text-white"
              >
                Lorem ipsum dolor, sit amet consectetur adipisicing elit.
                Magnam, repudiandae.
              </div>

              <div
                class="mt-4 mr-2 py-3 px-4 bg-blue-400 rounded-bl-3xl rounded-tl-3xl rounded-tr-xl text-white"
              >
                Lorem ipsum dolor sit amet consectetur adipisicing elit.
                Debitis, reiciendis!
              </div>
            </div>
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-8 w-8 rounded-full"
              alt=""
            />
          </div>
          <div class="flex justify-start mb-4">
            <img
              src="https://source.unsplash.com/vpOeXr5wmR4/600x600"
              class="object-cover h-8 w-8 rounded-full"
              alt=""
            />
            <div
              class="ml-2 py-3 px-4 bg-gray-400 rounded-br-3xl rounded-tr-3xl rounded-tl-xl text-white"
            >
              happy holiday guys!
            </div>
          </div>
        </div>
        <div class="py-5">
          <input
            class="w-full bg-gray-300 py-5 px-3 rounded-xl"
            type="text"
            placeholder="type your message here..."
          />
        </div>
      </div>
      <!-- end message -->
      <div class="w-2/5 border-l-2 px-5">
        <div class="flex flex-col">
          <div class="font-semibold text-xl py-4">Mern Stack Group</div>
          <img
            src="https://source.unsplash.com/L2cxSuKWbpo/600x600"
            class="object-cover rounded-xl h-64"
            alt=""
          />
          <div class="font-semibold py-4">Created 22 Sep 2021</div>
          <div class="font-light">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt,
            perspiciatis!
          </div>
          </div>
        </div>
      </div>
    </div>
</div>

How to build a Chat Messages with Tailwind CSS?

Install tailwind css of verion 2.0.2

Use the script html tag to import the script of Tailwind CSS of the version 2.0.2

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to build a Chat Messages component

  • mx-auto
  • px-5
  • py-5
  • flex
  • bg-white
  • border-b-2
  • text-2xl
  • w-1/2
  • bg-gray-100
  • py-3
  • w-full
  • h-12
  • w-12
  • p-2
  • bg-yellow-500
  • text-white
  • flex-row
  • flex-col
  • w-2/5
  • border-r-2
  • overflow-y-auto
  • py-4
  • px-2
  • py-2
  • border-2
  • border-gray-200
  • w-1/4
  • text-lg
  • text-gray-500
  • border-l-4
  • border-blue-400
  • mt-5
  • mb-4
  • mr-2
  • px-4
  • bg-blue-400
  • h-8
  • w-8
  • justify-start
  • ml-2
  • bg-gray-400
  • mt-4
  • bg-gray-300
  • px-3
  • border-l-2
  • text-xl
  • h-64

47 steps to build a Chat Messages component with Tailwind CSS

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

  2. Control the horizontal padding of an element to 1.25rem using the px-5 utilities.

  3. Control the vertical padding of an element to 1.25rem using the py-5 utilities.

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

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

  6. Control the border color of an element to b-2 using the border-b-2 utilities.

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

  8. Use w-1/2 to set an element to a fixed width(1/2).

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

  10. Control the vertical padding of an element to 0.75rem using the py-3 utilities.

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

  12. Use h-12 to set an element to a fixed height(3rem).

  13. Use w-12 to set an element to a fixed width(3rem).

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

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

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

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

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

  19. Use w-2/5 to set an element to a fixed width(2/5).

  20. Control the border color of an element to r-2 using the border-r-2 utilities.

  21. Use overflow-y-auto to allow vertical scrolling if needed.

  22. Control the vertical padding of an element to 1rem using the py-4 utilities.

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

  24. Control the vertical padding of an element to 0.5rem using the py-2 utilities.

  25. Control the border color of an element to 0.5rem using the border-2 utilities.

  26. Control the border color of an element to gray-200 using the border-gray-200 utilities.

  27. Use w-1/4 to set an element to a fixed width(1/4).

  28. Control the text color of an element to lg using the text-lg utilities.

  29. Control the text color of an element to gray-500 using the text-gray-500 utilities.

  30. Control the border color of an element to l-4 using the border-l-4 utilities.

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

  32. Control the margin on top side of an element to 1.25rem using the mt-5 utilities.

  33. Control the margin on bottom side of an element to 1rem using the mb-4 utilities.

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

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

  36. Control the background color of an element to blue-400 using the bg-blue-400 utilities.

  37. Use h-8 to set an element to a fixed height(2rem).

  38. Use w-8 to set an element to a fixed width(2rem).

  39. Use justify-start to justify items against the start of the container’s main axis.

  40. Control the margin on left side of an element to 0.5rem using the ml-2 utilities.

  41. Control the background color of an element to gray-400 using the bg-gray-400 utilities.

  42. Control the margin on top side of an element to 1rem using the mt-4 utilities.

  43. Control the background color of an element to gray-300 using the bg-gray-300 utilities.

  44. Control the horizontal padding of an element to 0.75rem using the px-3 utilities.

  45. Control the border color of an element to l-2 using the border-l-2 utilities.

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

  47. Use h-64 to set an element to a fixed height(16rem).

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to build a Chat Messages components, learn and follow along to implement your own components.