Styling text using Tailwind utility classes
Tailwind is a CSS framework that comes with a number of valuable classes by default. It enables us to compose and add classes as necessary.
Tailwind makes it easy to build our own design, unlike other CSS frameworks. It doesn’t dictate a certain appearance or design.
What are Tailwind utility classes?
Tailwind utility classes are varieties of ready-made UI. It provides a wide array of needs that allows you to build responsive web pages. It makes work easier as we only need to write a few codes to make a responsive website.
Text utility classes
With Tailwind, we can create personalized designs without coding CSS. This is done by applying pre-existing classes directly to our HTML.
Tailwind has many texts or typographical utility classes, which include:
- Font-size classes
- Font-family classes
- Font-style classes
- Letter spacing
- Text align
- Vertical align
- World break
- White space and many more
Note: if you don’t know how to set up a Tailwind development environment, Check here.
Code example
Let’s say we want a paragraph on the website to have the following styles:
font-sizeof14pxfont-styleofitalicfont-weightof500
Our p element will look like the following:
<p class="text-sm italic font-medium">content goes here...</p>
Code explanation
- The
text-smclass give the paragraphfont-size: 14px. - The
italicclass gives the paragraphfont-style: italic. - The
font-mediumclass gives the paragraphfont-weight: 500.
Tailwind makes it easy to write well-structured and concise codes with its utility classes. It's an efficient CSS framework.
Free Resources