CSS Tutorial: line-height πŸ“βœ¨

Introduction to line-height in CSS 🧡

The line-height property controls the vertical spacing between lines of text. It's one of the most important typography-related properties in CSS because it directly affects readability, aesthetics, and layout structure. Whether you’re working with paragraphs, headings, or UI text β€” mastering line-height is essential! πŸ”₯

Why Use line-height? πŸ€”

  • Improves readability in paragraphs πŸ“–
  • Prevents text from looking crowded or tight 🧠
  • Makes designs more visually balanced 🎨
  • Controls spacing in UI elements like buttons and inputs πŸ”˜

Syntax πŸ“Œ

Basic Syntax

selector {
  line-height: normal | <number> | <length> | <percentage>;
}

Note

Remember: line-height affects inline-level elements and text inside block-level elements.

Available Values 🧩

1. normal

The browser’s default line height. Usually between 1.1 and 1.4, depending on the font.

2. <number> (Recommended) πŸ‘

A multiplier of the font size. Example: line-height: 1.5; means 150% of the font size.

3. <length>

A fixed value such as 20px, 1.5rem, etc. Best for precise control, but not responsive.

4. <percentage>

Calculated based on the element’s font size. Example: 150%.

Examples πŸ”₯

1. Using Number (Most Common) ✨

Example: number value

p {
  line-height: 1.6;
}

2. Using Pixels (Fixed spacing) πŸ“

Example: pixel value

p {
  line-height: 24px;
}

3. Using Percentage (%)

Example: percentage value

p {
  line-height: 150%;
}

4. Tight vs Loose Line Height πŸ”

Tight and Loose Styles

.tight {
  line-height: 1.1;
}

.loose {
  line-height: 2;
}

Comparison Table πŸ“š

Value TypeExampleUsage
normalnormalDefault browser handling
number1.5Recommended for responsive layouts
length20pxPrecise control, but not flexible
percentage150%Similar to number, but expressed as %

Visual Example πŸ–ΌοΈ

How different line-heights look:

>>β€œReadable typography turns information into understanding.” β€” Anonymous πŸ“–βœ¨

Conclusion πŸŽ‰

The line-height property is crucial for improving text readability and visual structure. By adjusting spacing between lines, you can create clean, accessible, and beautifully designed content. Start experimenting with 1.4–1.8 for paragraphs β€” your readers will thank you! πŸš€