Course

Web Development
  • 1.1 Introduction to the Web
  • 2.1 HTML Basics
  • 2.2 Text & Content
  • 2.3 Layout & Grouping
  • 2.4 Lists & Tables
  • 2.5 Media & Embedding
  • 2.6 Forms
  • 2.7 Semantic HTML
  • 2.8 Accessibility & SEO
  • 3.1 CSS Introduction
  • 3.2 CSS Syntax
  • 3.3 CSS Selectors
  • 3.4 Typography
  • 3.5 Colors & Backgrounds
  • 3.6 Text Styling
  • 3.7 Box Model
  • 3.8 Units
  • 3.9 Display & Positioning
  • 3.10 Layout Systems
  • 3.11 Responsive Design
  • 3.12 Animations
  • 3.13 Modern CSS
  • 3.14 Performance & Accessibility
  • 3.15 Tailwind CSS Basics
  • 4.1 Introduction to JavaScript
  • 4.2 Variables & Scope
  • 4.3 Data Types
  • 4.4 Type Conversion
  • 4.5 Operators
  • 4.6 Control Flow
  • 4.7 Loops
  • 4.8 Functions
  • 4.9 Advanced Functions
  • 4.10 Objects & Arrays
  • 4.11 The this Keyword

3.6 Text Styling

Updated Jul 12, 2026

3.6 Text Styling

Updated Jul 12, 2026

Text styling in CSS controls how text appears on a webpage. It helps improve readability, visual hierarchy, and user experience.

Text styling includes:

  • Color
  • Text Alignment
  • Text Decoration
  • Text Transform
  • Text Spacing
  • Line Height
  • Text Shadow

Color

The color property changes the color of text.

color: value;

Example:

h1 {
    color: blue;
}

Using HEX:

h1 {
    color: #2563EB;
}

Using RGB:

h1 {
    color: rgb(37, 99, 235);
}

Using HSL:

h1 {
    color: hsl(220, 80%, 55%);
}

Example:

body {
    color: #333333;
}

All text becomes dark gray.


Text Alignment

The text-align property controls the horizontal alignment of text.

text-align: value;

Left (default):

text-align: left;

Center:

text-align: center;

Right:

text-align: right;

Justify:

text-align: justify;

Example:

.hero {
    text-align: center;
}

Text Decoration

The text-decoration property adds or removes decorative lines.

text-decoration: value;

Underline:

text-decoration: underline;

Overline:

text-decoration: overline;

Line-through:

text-decoration: line-through;

Remove link underline:

a {
    text-decoration: none;
}

Example:

.nav-link {
    text-decoration: none;
}

Text Transform

The text-transform property changes the letter casing.

text-transform: value;

Uppercase:

text-transform: uppercase;

Output:

FRONTEND DEVELOPMENT

Lowercase:

text-transform: lowercase;

Output:

frontend development

Capitalize:

text-transform: capitalize;

Output:

Frontend Development

None (default):

text-transform: none;

Example:

button {
    text-transform: uppercase;
}

Text Spacing

Text spacing controls the distance between letters and words.

Letter Spacing

The letter-spacing property controls spacing between characters.

letter-spacing: value;

Example:

h1 {
    letter-spacing: 2px;
}

Negative spacing:

letter-spacing: -1px;

Word Spacing

The word-spacing property controls spacing between words.

word-spacing: value;

Example:

p {
    word-spacing: 10px;
}

Example:

.hero-title {

    letter-spacing: 2px;

    word-spacing: 5px;

}

Line Height

The line-height property controls the spacing between lines of text.

line-height: value;

Example:

p {
    line-height: 2;
}

Common values:

line-height: 1.2;
line-height: 1.5;
line-height: 1.8;
line-height: 2;

Best practice:

body {
    line-height: 1.6;
}

Adequate line height makes paragraphs easier to read.


Text Shadow

The text-shadow property adds shadow effects to text.

Syntax:

text-shadow:
horizontal
vertical
blur
color;

Example:

h1 {

    text-shadow:
    2px 2px 5px gray;

}

Breakdown:

2px  → Horizontal Offset
2px  → Vertical Offset
5px  → Blur Radius
gray → Shadow Color

Example:

h1 {

    text-shadow:
    3px 3px 10px black;

}

Glow effect:

h1 {

    text-shadow:
    0 0 15px blue;

}

Multiple shadows:

h1 {

    text-shadow:

    1px 1px 2px black,

    0 0 10px blue;

}

Complete Example

HTML:

<h1>
    Frontend Development
</h1>

<p>
    Learn HTML, CSS, and JavaScript.
</p>

CSS:

h1 {

    color: #2563EB;

    text-align: center;

    text-transform: uppercase;

    letter-spacing: 2px;

    text-shadow:
    2px 2px 4px gray;

}

p {

    color: #555;

    line-height: 1.8;

}

Real-World Example

.hero-title {

    color: white;

    text-align: center;

    text-transform: uppercase;

    letter-spacing: 4px;

    text-shadow:
    0 2px 10px rgba(0,0,0,0.5);

}

Text Styling Best Practices

Use readable text colors.

color: #333333;

Avoid very light text on white backgrounds.


Use comfortable line height.

line-height: 1.6;

Keep text shadows subtle.

Good:

text-shadow:
0 2px 4px rgba(0,0,0,0.2);

Avoid:

text-shadow:
10px 10px 20px red;

Use text transformation carefully.

Good for headings:

text-transform: uppercase;

Avoid applying uppercase to long paragraphs.


Key Takeaway

Text styling controls how readable and visually appealing text appears.

h1 {

    color: #2563EB;

    text-align: center;

    text-transform: uppercase;

    letter-spacing: 2px;

    text-shadow:
    2px 2px 4px gray;

}

A well-designed website typically uses:

  • Readable colors
  • Proper alignment
  • Comfortable line height
  • Balanced letter and word spacing
  • Subtle text shadows
3.5 Colors & Backgrounds3.7 Box Model