- Published on
How To Build A News With Tailwind CSS From Scratch

- What is Tailwind CSS?
- The description of News ui component
- Why use Tailwind CSS to create a News ui component?
- The preview of News ui component
- The source code of News ui component
- How to create a News with Tailwind CSS?
- Install tailwind css of verion 2.2.4
- All the unility class needed to create a News component
- 34 steps to create a News 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 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
Control the text color of an element to gray-600 using the
text-gray-600
utilities.Control the horizontal padding of an element to 1.25rem using the
px-5
utilities.Control the vertical padding of an element to 6rem using the
py-24
utilities.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Set the maximum width/height of an element using the
max-w-7x1
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Use
w-full
to set an element to a 100% based width.Control the margin on bottom side of an element to 1rem using the
mb-4
utilities.Control the padding on all sides of an element to 1rem using the
p-4
utilities.Control the margin on bottom side of an element to 1.5rem using the
mb-6
utilities.Control the margin on bottom side of an element to 0rem at only large screen sizes using the
lg:mb-0
utilities.Control the text color of an element to 4xl at only small screen sizes using the
sm:text-4xl
utilities.Control the text color of an element to 5xl using the
text-5xl
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 gray-900 using the
text-gray-900
utilities.Use
h-1
to set an element to a fixed height(0.25rem).Use
w-20
to set an element to a fixed width(5rem).Control the background color of an element to indigo-500 using the
bg-indigo-500
utilities.Control the margin on all sides of an element to -1rem using the
-m-4
utilities.Use
xl:w-1/3
to set an element to a fixed width(1/3) at only extremely large screen sizes.Use
md:w-1/2
to set an element to a fixed width(1/2) at only medium screen sizes.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 1.5rem using the
p-6
utilities.Use
lg:h-60
to set an element to a fixed height(15rem) at only large screen sizes.Use
xl:h-56
to set an element to a fixed height(14rem) at only extremely large screen sizes.Use
md:h-64
to set an element to a fixed height(16rem) at only medium screen sizes.Use
sm:h-72
to set an element to a fixed height(18rem) at only small screen sizes.Use
xs:h-72
to set an element to a fixed height(18rem)undefined.Use
h-72
to set an element to a fixed height(18rem).Control the text color of an element to indigo-500 using the
text-indigo-500
utilities.Control the text color of an element to xs using the
text-xs
utilities.Control the text color of an element to lg using the
text-lg
utilities.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.