CSS Text Styling: Alignment, Case, & Spacing

Discover the fundamental CSS properties that give you full control over the appearance and readability of your text.

Lesson ProgressStep 1 of 6

CSS transforms text into a powerful design tool.

0 EXP

Welcome! Let's see how CSS transforms plain text into a stylish and readable design element.

.demo-text { 
  /* No styles yet */ 
}

Alignment (`text-align`)

The text-align property specifies the horizontal alignment of text within its container. This is one of the most fundamental properties for controlling text layout.

  • left: Aligns text to the left (default for LTR languages).
  • right: Aligns text to the right.
  • center: Centers the text.
  • justify: Stretches lines to have equal width, but can create ugly "rivers" of space.

System Check

Which `text-align` value is known to sometimes cause readability issues by creating large gaps between words?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏆
Text Aligner

Master text-align to position your text.

🏗️
Case Controller

Control capitalization with text-transform.

✍️
Spacing Pro

Demonstrate mastery of letter-spacing and line-height.

Mission: Style a Heading

Write a CSS rule for an `h1` element. Make it **centered**, uppercase, and give it **2px** of letter-spacing. Our AI assistant will provide real-time feedback.

A.D.A. Feedback:

> Awaiting input...

Challenge: Match Properties to Values

Drag the **CSS Property** (left) onto its corresponding **CSS Value** (right).

text-transform
text-align
line-height
Drop here:center;
Drop here:uppercase;
Drop here:1.6;

Challenge: Complete the Syntax

Fill in the missing properties and values to make the text readable.

.paragraph {
:;
:-0.5px;
}

Consult A.D.A.

Community Holo-Net

Beyond the Default: A Deep Dive into CSS Text Styling

When a browser renders plain HTML, it applies a very basic "user agent" stylesheet. This makes text readable, but it lacks personality and

When a browser renders plain HTML, it applies a very basic "user agent" stylesheet. This makes text readable, but it lacks personality and visual hierarchy. **CSS Typography** is the art of using CSS properties to style text, transforming it from a simple block of words into a powerful tool for communication, branding, and user experience.

In this article, we'll explore four of the most fundamental properties for controlling your text's layout, case, and spacing.

1. `text-align`: Controlling Horizontal Flow

The `text-align` property defines the horizontal alignment of text within its containing element. It's the first tool you'll reach for when positioning text.

  • left: The default value for left-to-right languages. Text is aligned to the left edge.
  • right: Text is aligned to the right edge. Useful for figure captions or special design elements.
  • center: Centers the text. This is most commonly used for headings, titles, and calls-to-action.
  • justify: Stretches each line (except the last) so that they have equal width, creating clean edges on both the left and right sides. While common in print, **use `justify` with caution on the web**. It can create awkward, large gaps between words (called "rivers"), which can severely harm readability.

There are also newer, logical values like start and end, which align text based on the document's writing direction (e.g., `start` is `left` in English but `right` in Arabic).

2. `text-transform`: Changing Capitalization

This property allows you to control the capitalization of text without changing the underlying HTML. This is excellent for accessibility and maintenance, as a screen reader will still read the original, properly-cased text.

  • uppercase: Transforms all characters to uppercase (ALL CAPS). Ideal for strong, impactful headings.
  • lowercase: Transforms all characters to lowercase.
  • capitalize: Capitalizes the first letter of each word. Useful for subheadings or navigation items.
  • none: The default. No transformation is applied.

3. `letter-spacing`: The Space Between Characters

Known as **"tracking"** in graphic design, `letter-spacing` adjusts the space between individual characters. It can have a dramatic effect on readability and style.

You can provide a length value (like px, em, or rem).

  • Positive values (e.g., 2px) spread letters apart, creating an airy, elegant, or emphatic feel. This is often applied to uppercase headings.
  • Negative values (e.g., -0.5px) pull letters closer together. This "tighter" tracking is often used in large display fonts to improve visual balance.

4. `line-height`: The Space Between Lines

Known as **"leading"** in print design, `line-height` controls the vertical space between lines of text. This is arguably the most important property for the readability of long-form text.

While you *can* use units like px or em, the **best practice** is to use a **unitless number**:

✔️ Good Practice

p {
  font-size: 16px;
  line-height: 1.6;
}

The line height will be 1.6 * 16px = 25.6px. This ratio is inherited by child elements, so it always scales correctly.

❌ Bad Practice

p {
  font-size: 16px;
  line-height: 26px;
}

A fixed `26px` height is inherited. If a child element has a larger font size, its text will overlap, breaking the layout.

For body text, a `line-height` between `1.5` and `1.8` is generally recommended for optimal readability.

Key Takeaway: Combine these properties to create a clear visual hierarchy. Use `text-align` and `text-transform` for headings. Use `line-height` for readable paragraphs. Use `letter-spacing` to add a final touch of polish.

CSS Text Styling Glossary

text-align
Sets the horizontal alignment of inline content (like text). Common values are left, right, center, and justify.
text-transform
Controls the capitalization of text. Values include uppercase, lowercase, capitalize, and none.
letter-spacing
Adjusts the horizontal space between individual characters. Also known as "tracking". Can be a positive or negative length.
line-height
Sets the vertical distance between lines of text. It's best practice to use a unitless number (e.g., 1.6) which acts as a multiplier of the element's font-size.
word-spacing
Similar to letter-spacing, but adjusts the space between words, not characters.
text-indent
Specifies the indentation of the first line of text in a block container. Often used to indent paragraphs (e.g., text-indent: 2em;).
text-decoration
A shorthand property for setting text-decoration-line, text-decoration-color, and text-decoration-style. Most commonly used to add or remove underlines (e.g., text-decoration: none;).
white-space
Controls how whitespace inside an element is handled. The value nowrap, for example, prevents text from wrapping to the next line.
Leading
A typography term for the vertical space between lines of text. This is controlled in CSS by the line-height property.
Tracking
A typography term for adjusting the spacing uniformly across a range of characters. This is controlled in CSS by the letter-spacing property.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching CSS and building robust, well-designed web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest CSS specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!