How to Style Text in HTML and CSS: A Step-by-Step Guide

In this lesson, we explore the fundamentals of text styling using HTML and CSS. We’ll cover everything from setting fonts and sizes to adding spacing, aligning text, and working with special characters. By the end, you’ll be equipped to replicate complex designs with confidence. Let’s dive in!


1. Setting Up Your Project

Create a New HTML File

  1. Start by creating a new file called text.html.
  2. Open the file in your browser (e.g., Google Chrome).
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Text Styling</title>
    <style>
        /* CSS will go here */
    </style>
</head>
<body>
    <p class="video-title">Sample Text from YouTube</p>
</body>
</html>

2. Styling Text Using CSS

Change the Font

  • CSS Property: font-family
  • Default font: Times New Roman
  • Example: Change to Arial.
.video-title {
    font-family: Arial, sans-serif;
}

Adjust Font Size

  • CSS Property: font-size
  • Example: Increase font size to 30px.
.video-title {
    font-size: 30px;
}

Make Text Bold

  • CSS Property: font-weight
.video-title {
    font-weight: bold;
}

Italicize Text

  • CSS Property: font-style
.video-title {
    font-style: italic;
}

Center Align Text

  • CSS Property: text-align
.video-title {
    text-align: center;
}

3. Adding Line Height and Wrapping Text

Adjust Line Height

  • CSS Property: line-height
.video-title {
    line-height: 1.5;
}

Set a Width for Text Wrapping

  • CSS Property: width
.video-title {
    width: 300px;
}

4. Adding Special Characters

Use HTML Entities for Symbols

  • Middle Dot: &middot;
  • Checkmark: &#10003;
<p class="video-stats">3.4M views &middot; Verified &#10003;</p>

5. Fine-Tuning Margins and Spacing

Reset Default Margins

Paragraphs have default margins. To remove them:

.video-title {
    margin: 0;
}

Add Custom Margins

Set precise spacing with margin.

.video-title {
    margin-bottom: 5px;
}

6. Styling Additional Paragraphs

Add classes to paragraphs and apply specific styles. For example:

<p class="video-description">This is a detailed description of the video content.</p>
.video-description {
    font-family: Arial, sans-serif;
    font-size: 14px;
    color: gray;
    width: 280px;
    line-height: 1.6;
}

7. Tips for Complex Designs

  • Inspect Elements: Use browser developer tools to check and copy styles.
  • Google for Help: Search for CSS properties when unsure (e.g., “CSS text italic”).
  • Iterate and Test: Adjust values like font size, width, and margins for a better match.

Conclusion

By combining HTML and CSS, you can achieve professional text styling that aligns with your design goals. From fonts and alignment to spacing and special characters, these tools allow you to bring your creative vision to life.

Ibad Ur Rahman
Ibad Ur Rahmanhttps://gadgetsfocus.com
Ibad Ur Rahman is a tech enthusiast and the lead editor at GadgetsFocus. With years of experience diving deep into consumer electronics, Ibad specializes in breaking down complex tech specifications into clear, actionable advice. His rigorous approach to aggregating real-world data and testing insights ensures that readers get the unvarnished truth about the latest smartphones, laptops, and smart home gadgets.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertisement

Latest posts

No Sound on Windows 11 (“No Audio Output Device Is Installed”) or Mac Speakers Not Working? 7 Verified HDMI, Driver & CoreAudio Fixes (2026)

Verdict: When Windows 11 or macOS suddenly produces no sound—or displays a red "X" speaker icon reading "No audio output device is installed"—the cause...

November 2026 New AI Models Guide: OpenAI GPT-6 Cyber, Gemini Omni 1.2 Flash, GPT-Image-2.6, Kimi K3.1 Pro & Meta Muse Ember Explained

Verdict: Beyond the flagship reasoning launches of Claude Fable 5.2 (November 9) and Gemini 4 Carbon (November 10), the first 10 days of November...

Claude Fable 5.2 vs Gemini 4 Carbon vs GPT-6 Astra (November 2026): Specs, Benchmarks, Context Limits & API Pricing Compared

Verdict: Between the frontier reasoning models available in mid-November 2026, Anthropic's Claude Fable 5.2 (claude-fable-5-2, released November 9, 2026) and Google DeepMind's Gemini 4...