TechTicket Logo
CSS Fundamentals and Modern Layouts

Session 3 — Colors, Backgrounds, Fonts, and Typography

🎯 Session Overview

Welcome to Session 3! Now that you know how to target HTML elements using CSS selectors, it's time to make them look beautiful.

A website without colors and fonts looks like a boring text document from 1995. In this session, you will learn how to:

⏪ Quick Recap: Session 2

Let's remember how we aim our CSS rules:

🎨 CSS Colors: Painting the Web

The easiest property in CSS is color. It changes the color of the text inside an element.

p {
    color: red;
}

But typing "red" or "blue" is limiting. What if you want a specific shade of neon cyan? CSS gives us three main ways to write colors:

1. Color Names

CSS knows about 140 basic color names like red, blue, green, and even weird ones like tomato or dodgerblue.

2. HEX Colors (Hexadecimal)

This is the most popular format for professional designers. It starts with a hashtag # followed by 6 letters and numbers. It represents the mix of Red, Green, and Blue.

h1 {
    color: #ff0000; /* This is pure red */
    color: #00f0ff; /* This is bright cyan */
}

3. RGB and RGBA (Transparency)

RGB stands for Red, Green, Blue. You mix values from 0 to 255.
RGBA adds an "Alpha" channel at the end, which controls transparency (from 0.0 invisible to 1.0 solid).

h2 {
    color: rgb(255, 0, 0); /* Solid red */
    color: rgba(255, 0, 0, 0.5); /* 50% see-through red */
}

Color Formats Explained

HEX #ec4899 RGB rgb(59,130,246) RGBA rgba(16,185,129,0.5)

🖼️ Background Styling

While color changes the text, background-color paints the box behind the text.

body {
    background-color: #111111; /* Very dark gray */
}

.highlight-box {
    background-color: rgba(0, 255, 255, 0.2);
    color: white;
}

You can also use images as backgrounds instead of flat colors! Modern websites use these three properties together:

✨ Interactive Demo: The Paint Bucket

Click the buttons below to change the background and text color of the demo box using different formats!

Style Me!

🔤 Fonts in CSS

Different fonts give a website its personality. A news website needs a clean, serious font. A gaming website might want a futuristic, blocky font.

We change the font using the font-family property.

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

This is called a Font Fallback. The browser reads from left to right:

  1. "Do I have Helvetica installed on my computer?" If yes, use it.
  2. If no, "Do I have Arial?" If yes, use it.
  3. If no, just use any generic sans-serif (fonts without little feet on the letters) that I have.

Using Google Fonts

What if you want a super cool font that nobody has installed on their computer? You can borrow it from Google for free!

  1. Go to fonts.google.com, find a font, and copy the <link> tag they provide.
  2. Paste that link into the <head> of your HTML file.
  3. Use the exact font-family name they tell you in your CSS!
This text uses a Google Font called 'Pacifico'!

📏 Typography: Making Text Readable

Typography is the art of arranging text. Even if you pick a cool font, if the words are squished together, nobody will read it.

Here are the 4 essential properties to make your text look professional:

font-size: 24px; Makes the text bigger or smaller. font-weight: bold; Controls the thickness (normal, bold, 900). line-height: 1.6; Space between lines of text. text-align: center; Aligns text (left, center, right).
h1 {
    font-size: 36px;
    font-weight: bold;
    text-align: center;
    letter-spacing: 2px; /* Spreads letters apart */
}

p {
    line-height: 1.6; /* 1.6x the normal space between lines */
    text-decoration: underline; /* Underlines the text */
}

Pro Tip: Setting line-height: 1.5 or 1.6 on your body element instantly makes paragraphs 10x easier to read!

🏋️‍♂️ Practice Exercises

Open your code editor. Make sure your HTML has an h1, a p, and your CSS file is linked!

Exercise 1: Paint the Title

Target all h1 headings. Change their text color to a HEX code of your choice (Search "Color Picker" on Google to find one!).

h1 { color: #ff00ff; }

Exercise 2: Set the Stage

Target the body element. Give the entire page a dark background color, and make all the text inside it white.

body { background-color: #222222; color: white; }

Exercise 3: Make it Readable

Target your paragraphs (p). Change their font to Arial, make the font size 18px, and increase the line-height to 1.6.

p { font-family: Arial; font-size: 18px; line-height: 1.6; }

🔥 Mini Challenge: The Glass Text

Create a giant h1 heading that says "GHOST".

Your Goal: Make the text semi-transparent so that you can kind of see the background color through the letters. Use the RGBA format!

Set the A (Alpha) value to 0.5 for 50% transparency.
h1 { color: rgba(255, 255, 255, 0.5); }

🏠 Homework Project: Styled Profile Page

Build a beautiful personal profile webpage using everything we learned today!

📝 Session Summary

⬅ Previous Session Next Session ➡