Published on

How To Build A Music Player With Tailwind CSS From Scratch

Tags
Music player

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 Music player ui component

Simple header / music player

Why use Tailwind CSS to make a Music player ui component?

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

The preview of Music player ui component

Free download of the Music player's source code

The source code of Music player ui component

<div class="min-h-screen bg-gray-100 flex flex-col items-center justify-center">

  <div class="relative max-w-xl w-full h-36 bg-white rounded-lg shadow-lg overflow-hidde mb-32">
    <div class="absolute inset-0 rounded-lg overflow-hidden bg-red-200">
      <img src="https://images.unsplash.com/photo-1543794327-59a91fb815d1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&h=200&q=80" alt="">
      <div class="absolute inset-0 backdrop backdrop-blur-10 bg-gradient-to-b from-transparent to-black">
        
      </div>
    </div>
    <div class="absolute flex space-x-6 transform translate-x-6 translate-y-8">
      <div class="w-36 h-36 rounded-lg shadow-lg overflow-hidden">
        <img src="https://images.unsplash.com/photo-1543794327-59a91fb815d1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=200&h=200&q=80" alt="">
      </div>
      <div class="text-white pt-12">
        <h3 class="font-bold">Album</h3>
        <div class="text-sm opacity-60">Super Interpret</div>
        <div class="mt-8 text-gray-400">
          <div class="flex items-center space-x-2 text-xs">
            <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 18v-6a9 9 0 0 1 18 0v6"></path><path d="M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"></path></svg>
            <span>Easy listening</span>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="max-w-xl bg-white rounded-lg shadow-lg overflow-hidden">
    <div class="relative">
      <img
        src="https://images.unsplash.com/photo-1500099817043-86d46000d58f?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=800&h=250&q=80"
        class="object-cover">
      <div class="absolute p-4 inset-0 flex flex-col justify-end bg-gradient-to-b from-transparent to-gray-900 backdrop backdrop-blur-5 text-white">
        <h3 class="font-bold">Super Artist</h3>
        <span class="opacity-70">Albumtitle</span>
      </div>
    </div>
    <div>
      <div class="relative h-1 bg-gray-200">
        <div class="absolute h-full w-1/2 bg-green-500 flex items-center justify-end">
          <div class="rounded-full w-3 h-3 bg-white shadow"></div>
        </div>
      </div>
    </div>
    <div class="flex justify-between text-xs font-semibold text-gray-500 px-4 py-2">
      <div>
        1:50
      </div>
      <div class="flex space-x-3 p-2">
        <button class="focus:outline-none">
          <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="19 20 9 12 19 4 19 20"></polygon><line x1="5" y1="19" x2="5" y2="5"></line></svg>
        </button>
        <button class="rounded-full w-8 h-8 flex items-center justify-center pl-0.5 ring-2 ring-gray-100 focus:outline-none">
          <svg class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
        </button>
        <button class="focus:outline-none">
          <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 4 15 12 5 20 5 4"></polygon><line x1="19" y1="5" x2="19" y2="19"></line></svg>
        </button>
      </div>
      <div>
        3:00
      </div>
    </div>
    <ul class="text-xs sm:text-base divide-y border-t cursor-default">
      <li class="flex items-center space-x-3 hover:bg-gray-100">
        <button class="p-3 hover:bg-green-500 group focus:outline-none">
          <svg class="w-4 h-4 group-hover:text-white" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
        </button>
        <div class="flex-1">
          Artist - Title
        </div>
        <div class="text-xs text-gray-400">
          2:58
        </div>
        <button class="focus:outline-none pr-4 group">
          <svg class="w-4 h-4 group-hover:text-green-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 15v4c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2v-4M17 9l-5 5-5-5M12 12.8V2.5"/></svg>
        </button>
      </li>
      <li class="flex items-center space-x-3 hover:bg-gray-100">
        <button class="p-3 hover:bg-green-500 group focus:outline-none">
          <svg class="w-4 h-4 group-hover:text-white" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
        </button>
        <div class="flex-1">
          Artist - Title
        </div>
        <div class="text-xs text-gray-400">
          2:58
        </div>
        <button class="focus:outline-none pr-4 group">
          <svg class="w-4 h-4 group-hover:text-green-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 15v4c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2v-4M17 9l-5 5-5-5M12 12.8V2.5"/></svg>
        </button>
      </li>
    </ul>
  </div>
</div>

How to make a Music player 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 make a Music player component

  • min-h-screen
  • bg-gray-100
  • flex
  • flex-col
  • relative
  • max-w-xl
  • w-full
  • h-36
  • bg-white
  • mb-32
  • absolute
  • overflow-hidden
  • bg-red-200
  • bg-gradient-to-b
  • w-36
  • text-white
  • pt-12
  • text-sm
  • mt-8
  • text-gray-400
  • text-xs
  • w-4
  • h-4
  • p-4
  • h-1
  • bg-gray-200
  • h-full
  • w-1/2
  • bg-green-500
  • w-3
  • h-3
  • text-gray-500
  • px-4
  • py-2
  • p-2
  • w-8
  • h-8
  • pl-0.5
  • w-5
  • h-5
  • sm:text-base
  • border-t
  • hover:bg-gray-100
  • p-3
  • hover:bg-green-500
  • group-hover:text-white
  • flex-1
  • pr-4
  • group-hover:text-green-600

49 steps to make a Music player component with Tailwind CSS

  1. Set the minimum width/height of an element using the min-h-screen utilities.

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

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

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

  5. Use relative to position an element according to the normal flow of the document.

  6. Set the maximum width/height of an element using the max-w-xl utilities.

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

  8. Use h-36 to set an element to a fixed height(9rem).

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

  10. Control the margin on bottom side of an element to 8rem using the mb-32 utilities.

  11. 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.

  12. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

  13. Control the background color of an element to red-200 using the bg-red-200 utilities.

  14. Control the background color of an element to gradient-to-b using the bg-gradient-to-b utilities.

  15. Use w-36 to set an element to a fixed width(9rem).

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

  17. Control the padding on top side of an element to 3rem using the pt-12 utilities.

  18. Control the text color of an element to sm using the text-sm utilities.

  19. Control the margin on top side of an element to 2rem using the mt-8 utilities.

  20. Control the text color of an element to gray-400 using the text-gray-400 utilities.

  21. Control the text color of an element to xs using the text-xs utilities.

  22. Use w-4 to set an element to a fixed width(1rem).

  23. Use h-4 to set an element to a fixed height(1rem).

  24. Control the padding on all sides of an element to 1rem using the p-4 utilities.

  25. Use h-1 to set an element to a fixed height(0.25rem).

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

  27. Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

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

  29. Control the background color of an element to green-500 using the bg-green-500 utilities.

  30. Use w-3 to set an element to a fixed width(0.75rem).

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

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

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

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

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

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

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

  38. Adjust the left padding of the element to 0.5 using the pl-0.5 utilities class

  39. Use w-5 to set an element to a fixed width(1.25rem).

  40. Use h-5 to set an element to a fixed height(1.25rem).

  41. Control the text color of an element to base at only small screen sizes using the sm:text-base utilities.

  42. Control the border color of an element to t using the border-t utilities.

  43. Control the background color of an element to gray-100 using the hover:bg-gray-100 utilities on hover.

  44. Control the padding on all sides of an element to 0.75rem using the p-3 utilities.

  45. Control the background color of an element to green-500 using the hover:bg-green-500 utilities on hover.

  46. Control the text color of an element to whiteundefined using the group-hover:text-white utilities.

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

  48. Control the padding on right side of an element to 1rem using the pr-4 utilities.

  49. Control the text color of an element to green-600undefined using the group-hover:text-green-600 utilities.

Conclusion

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