Tailwind Line Height

Tailwind line height allows you to adjust the vertical space between lines of text. In this article, we will examine Tailwind’s line height with examples.

In Tailwind CSS, the line-height utility class is used to adjust the spacing between lines of text within an element.

Tailwind Line Height

It sets the line-height CSS property to a specified value, which determines the amount of space between lines of text.

Using the line-height utility class can help improve the readability and aesthetics of text on a webpage.



What is Line Height?

Line height, also known as leading, refers to the vertical space between lines of text in a block.

This spacing can be adjusted to create various effects, such as improving readability, emphasizing text, or creating a unique design style.

In traditional CSS, line height is specified by the line-height property and it takes a value in pixels, ems, or other units.


Tailwind Line Height Classes

ClassesOverview
leading-3This class is used to set the line height value to 0.75rem or 12px.
leading-4The line height value is set to 1rem or 16px using this class.
leading-5By using this class, you can set the line height value to 1.25rem or 20px.
leading-6The line height of the line is set to 1.5 rem or 24px with this class.
leading-7To set the line height value to 1.75rem or 28px, this class is used.
leading-8Its purpose is to set the line height value to 2rem or 32px.
leading-9A line height of 2.25rem or 36px is applied using this class.
leading-10Using this class, you can apply a line height value of 2.5rem or 40px.
leading-noneThis class sets the line-height of an element to 1, meaning there will be no additional spacing between lines of text within the element.
leading-tightThe leading-tight class sets a tight line-height value for an element. This means that the space between the lines of text will be minimal. Its value is 1.25.
leading-snugThis class sets line height to a relatively small value while still ensuring that the text doesn’t overlap. It has a value of 1.375.
leading-normalDefault line-height of 1.5 is specified in this class.
leading-relaxedIn this case, the line height value is defined as 1.75 that is slightly more spacious than normal.
leading-looseThis class sets the line-height CSS property to 2, which is 4/3 times the default value.

Tailwind Line Height Fixed

These utilities allow you to set a specific line-height for an element, regardless of its current font-size.

Syntax

<element class="leading-{size}">...</element>

This example showcases the implementation of some fixed line height utility classes such as leading-3, leading-5, leading-7 and leading-9:

Example: 

<!DOCTYPE html> <html> <head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-medium text-slate-800 my-3">Line Height in Tailwind</p> <div class="bg-gray-200 p-2 rounded text-start font-medium"> <p class="p-2">leading-3:<span class="leading-3"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> <p class="p-2">leading-5:<span class="leading-5"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> <p class="p-2">leading-7:<span class="leading-7"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> <p class="p-2">leading-9:<span class="leading-9"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> </div> </body> </html>

Tailwind Line Height Relative

These utilities provide a relative line-height based on the current font-size of the element.

Syntax

<element class="leading-{keyword}">...</element>

The following example portrays the usage of some relative line height utility classes such as leading-none, leading-snug, leading-relaxed and leading-loose:

Example: 

<!DOCTYPE html> <html> <head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-medium text-slate-800 my-3">Line Height in Tailwind</p> <div class="bg-gray-200 p-2 rounded text-start font-medium"> <p class="p-2">leading-none:<span class="leading-none"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> <p class="p-2">leading-snug:<span class="leading-snug"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> <p class="p-2">leading-relaxed:<span class="leading-relaxed"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> <p class="p-2">leading-loose:<span class="leading-loose"> Maecenas et mattis lacus, ac tincidunt tellus. Sed vehicula nulla massa, ac tempus eros ullamcorper vitae. Donec pellentesque arcu massa, a fringilla lorem suscipit vitae. </span> </p> </div> </body> </html>
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *