Skip to content

Styling Text with CSS | Lecture 15

Styling Text with CSS

Let’s begin with Lecture 15 of the HTML5 & CSS3 series. Styling Text with CSS โ€“ Font Families, Sizes, and Styles. This lecture is for absolute beginners; even kids can follow along and understand.

๐ŸŽฏ Objective:

By the end of this lecture, you will:

  • Understand how to change font families, sizes, and styles using CSS
  • Know how to make text bold, italic, or underlined
  • Be able to align text (left, center, right)
  • Apply these styles to your webpage for a clean, readable look

๐Ÿ“ What is Text Styling?

Text styling helps your website appear neat, readable, and visually appealing.

Think of it like this:

Just like you choose different pens or markers when drawing or writing, CSS lets you style your text so it looks just right!

๐Ÿ–‹๏ธ Changing Font Family

The font-family The property lets you choose which type of font to use.

Example:
body {
    font-family: Arial, sans-serif;
}

You can also use fun fonts:

h1 {
    font-family: 'Comic Sans MS', cursive, sans-serif;
}
Common Web-Safe Fonts:
  • Arial
  • Times New Roman
  • Verdana
  • Georgia
  • Courier New
  • Tahoma
  • Lucida Console

๐Ÿ’ก Pro Tip: Always include a fallback font, like sans-serif, in case the first one isnโ€™t available.

๐Ÿ”ค Setting Font Size

Use the font-size property to control how big or small your text appears.

Example:
p {
    font-size: 16px;
}

You can also use:

  • px โ€“ pixels (most common)
  • % โ€“ percentage of default size
  • em โ€“ relative to the parent element
  • rem โ€“ relative to the root element
๐Ÿ–Œ๏ธ Text Style Properties
PropertyDescriptionExample
font-weightMakes text bold or normalfont-weight: bold;
font-styleMakes text italicfont-style: italic;
text-decorationAdds underline, line-throughtext-decoration: underline;
text-alignAligns text left, center, righttext-align: center;
๐Ÿ’ป Try This: Make Your Page Look Like a Magazine Article

Letโ€™s update your homepage (index.html) to look like a styled article.

Step 1: Open index.html

Make sure your HTML looks something like this:

<!DOCTYPE html>
<html>
<head>
    <title>Welcome</title>
    <style>
        body {
            background-color: hsl(210, 30%, 95%);
            font-family: Arial, sans-serif;
            padding: 20px;
        }

        h1 {
            color: hsl(350, 100%, 40%);
            border-bottom: 2px solid #007BFF;
        }

        h2 {
            color: rgb(255, 87, 34);
            background-color: rgba(255, 255, 0, 0.3);
            padding: 5px;
        }

        p {
            color: #2e2e2e;
            font-size: 16px;
        }

        .highlight {
            background-color: hsla(60, 100%, 75%, 0.5);
            padding: 5px;
        }
    </style>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>Hello! In this article, I'm going to share some fun facts about animals.</p>

    <h2>Cats</h2>
    <p>Cats are amazing pets...</p>

    <h2>Dogs</h2>
    <p>Dogs are loyal friends...</p>

    <h2>Birds</h2>
    <p class="highlight">Birds can fly and sing beautiful songs. Some birds even talk!</p>
</body>
</html>
Step 2: Update Your CSS Styles

Replace the <style> block with this updated version:

<style>
    body {
        background-color: hsl(210, 30%, 95%);
        font-family: 'Georgia', serif;
        padding: 30px;
        line-height: 1.6;
    }

    h1 {
        font-family: 'Comic Sans MS', cursive, sans-serif;
        color: hsl(350, 100%, 40%);
        font-size: 36px;
        text-align: center;
        border-bottom: 3px solid hsl(200, 80%, 50%);
        padding-bottom: 10px;
    }

    h2 {
        font-family: 'Trebuchet MS', sans-serif;
        color: rgb(255, 87, 34);
        font-size: 24px;
        font-weight: bold;
        font-style: italic;
    }

    p {
        font-size: 18px;
        color: #2e2e2e;
        text-align: justify;
    }

    .highlight {
        background-color: hsla(60, 100%, 75%, 0.5);
        padding: 5px;
        font-weight: bold;
        text-decoration: underline;
    }
</style>
Step 3: Run with Live Server

Right-click the code โ†’ Show All Commands โ†’ Launch Live Server

๐ŸŽ‰ You’ve transformed your page into a beautifully styled magazine-style article!

Styling Text with CSS
A kid typing into a computer screen choosing from a menu labeled

๐Ÿงช Try It Yourself!

  1. Change the body font to 'Verdana', sans-serif.
  2. Make one of the paragraphs appear in all caps using text-transform: uppercase;
  3. Add text-shadow to the heading to give it a glowing effect.
  4. Use text-align: right on one of the paragraphs.
๐Ÿš€ Next Lecture Preview:

In Lecture 16, weโ€™ll learn about semantic HTML tags like <header>, <footer>, <nav>, and <main> โ€” so your website becomes more meaningful and easier to read by both humans and search engines!

Stay Updated

If you found this information useful, donโ€™t forget to bookmark this page and Share and leave your feedback in the comment section below.

HTML5 and CSS3 Compleate Series