Published on

How To Build A News With Tailwind CSS From Scratch

News

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 News ui component

News - responsive grid

Why use Tailwind CSS to create a News ui component?

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

The preview of News ui component

Free download of the News's source code

The source code of News ui component

<section class="text-gray-600 body-font">
  <div class="container px-5 py-24 mx-auto max-w-7x1">
    <div class="flex flex-wrap w-full mb-4 p-4">
      <div class="w-full mb-6 lg:mb-0">
        <h1 class="sm:text-4xl text-5xl font-medium font-bold title-font mb-2 text-gray-900">News</h1>
        <div class="h-1 w-20 bg-indigo-500 rounded"></div>
      </div>
    </div>
    <div class="flex flex-wrap -m-4">
      <div class="xl:w-1/3 md:w-1/2 p-4">
        <div class="bg-white p-6 rounded-lg">
          <img class="lg:h-60 xl:h-56 md:h-64 sm:h-72 xs:h-72 h-72  rounded w-full object-cover object-center mb-6" src="https://kuyou.id/content/images/ctc_2020021605150668915.jpg" alt="Image Size 720x400">
          <h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
          <h2 class="text-lg text-gray-900 font-medium title-font mb-4">Chichen Itza</h2>
          <p class="leading-relaxed text-base">Fingerstache flexitarian street art 8-bit waistcoat. Distillery hexagon disrupt edison bulbche.</p>
        </div>
      </div>
      <div class="xl:w-1/3 md:w-1/2 p-4">
        <div class="bg-white p-6 rounded-lg">
          <img class="lg:h-60 xl:h-56 md:h-64 sm:h-72 xs:h-72 h-72 rounded w-full object-cover object-center mb-6" src="https://asset.kompas.com/crops/Pk_pN6vllxXy1RshYsEv74Q1BYA=/56x0:1553x998/750x500/data/photo/2021/06/16/60c8f9d68ff4a.jpg" alt="Image Size 720x400">
          <h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
          <h2 class="text-lg text-gray-900 font-medium title-font mb-4">Colosseum Roma</h2>
          <p class="leading-relaxed text-base">Fingerstache flexitarian street art 8-bit waistcoat. Distillery hexagon disrupt edison bulbche.</p>
        </div>
      </div>
      <div class="xl:w-1/3 md:w-1/2 p-4">
        <div class="bg-white p-6 rounded-lg">
          <img class="lg:h-60 xl:h-56 md:h-64 sm:h-72 xs:h-72 h-72 rounded w-full object-cover object-center mb-6" src="https://images.immediate.co.uk/production/volatile/sites/7/2019/07/33-GettyImages-154260931-216706f.jpg?quality=90&resize=768%2C574" alt="Image Size 720x400">
          <h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
          <h2 class="text-lg text-gray-900 font-medium title-font mb-4">Great Pyramid of Giza</h2>
          <p class="leading-relaxed text-base">Fingerstache flexitarian street art 8-bit waistcoat. Distillery hexagon disrupt edison bulbche.</p>
        </div>
      </div>
      <div class="xl:w-1/3 md:w-1/2 p-4">
        <div class="bg-white p-6 rounded-lg">
          <img class="lg:h-60 xl:h-56 md:h-64 sm:h-72 xs:h-72 h-72 rounded w-full object-cover object-center mb-6" src="https://wisatamuda.com/wp-content/uploads/2019/02/1-Golden-Gate-Bridge-Gambar-dan-Foto-Tempat-Wisata-Terbaik-di-San-Fransisco-USA.jpg" alt="Image Size 720x400">
          <h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
          <h2 class="text-lg text-gray-900 font-medium title-font mb-4">San Francisco</h2>
          <p class="leading-relaxed text-base">Fingerstache flexitarian street art 8-bit waistcoat. Distillery hexagon disrupt edison bulbche.</p>
        </div>
      </div>
    </div>
  </div>
</section>

How to create a News with Tailwind CSS?

Install tailwind css of verion 2.2.4

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

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

All the unility class needed to create a News component

  • text-gray-600
  • px-5
  • py-24
  • mx-auto
  • max-w-7x1
  • flex
  • flex-wrap
  • w-full
  • mb-4
  • p-4
  • mb-6
  • lg:mb-0
  • sm:text-4xl
  • text-5xl
  • mb-2
  • text-gray-900
  • h-1
  • w-20
  • bg-indigo-500
  • -m-4
  • xl:w-1/3
  • md:w-1/2
  • bg-white
  • p-6
  • lg:h-60
  • xl:h-56
  • md:h-64
  • sm:h-72
  • xs:h-72
  • h-72
  • text-indigo-500
  • text-xs
  • text-lg
  • text-base

34 steps to create a News component with Tailwind CSS

  1. Control the text color of an element to gray-600 using the text-gray-600 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 6rem using the py-24 utilities.

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

  5. Set the maximum width/height of an element using the max-w-7x1 utilities.

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

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

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

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

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

  11. Control the margin on bottom side of an element to 1.5rem using the mb-6 utilities.

  12. Control the margin on bottom side of an element to 0rem at only large screen sizes using the lg:mb-0 utilities.

  13. Control the text color of an element to 4xl at only small screen sizes using the sm:text-4xl utilities.

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

  15. Control the margin on bottom side of an element to 0.5rem using the mb-2 utilities.

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

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

  18. Use w-20 to set an element to a fixed width(5rem).

  19. Control the background color of an element to indigo-500 using the bg-indigo-500 utilities.

  20. Control the margin on all sides of an element to -1rem using the -m-4 utilities.

  21. Use xl:w-1/3 to set an element to a fixed width(1/3) at only extremely large screen sizes.

  22. Use md:w-1/2 to set an element to a fixed width(1/2) at only medium screen sizes.

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

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

  25. Use lg:h-60 to set an element to a fixed height(15rem) at only large screen sizes.

  26. Use xl:h-56 to set an element to a fixed height(14rem) at only extremely large screen sizes.

  27. Use md:h-64 to set an element to a fixed height(16rem) at only medium screen sizes.

  28. Use sm:h-72 to set an element to a fixed height(18rem) at only small screen sizes.

  29. Use xs:h-72 to set an element to a fixed height(18rem)undefined.

  30. Use h-72 to set an element to a fixed height(18rem).

  31. Control the text color of an element to indigo-500 using the text-indigo-500 utilities.

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

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

  34. Control the text color of an element to base using the text-base utilities.

Conclusion

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