Lab 02: CSS Selectors & Specificity

🎯 Objective

Master HTML text elements including headings (h1h6), paragraphs (p), inline elements (span, strong, em), and text formatting tags.

📚 Background

Text is the core of web content. HTML provides semantic tags that give meaning to text — not just style it. Using the right tag (e.g., <strong> vs <b>) matters for accessibility and SEO.

⏱️ Estimated Time

25 minutes

📋 Prerequisites

  • Completed Lab 1 (HTML Document Structure)

🛠️ Tools Used

  • Python 3 (validation and server)

  • Web browser

🔬 Lab Instructions

Step 1: Create the lab file

Step 2: Add heading hierarchy

💡 There should only be one <h1> per page. Use headings in order (don't skip from h1 to h4).

Step 3: Add paragraphs and whitespace

💡 <br> and <hr> are void elements — they don't need closing tags.

Step 4: Add inline text formatting

Step 5: Use <span> for inline grouping

💡 <span> is a generic inline container with no semantic meaning. Use it when you need to style or target specific inline text.

Step 6: Add preformatted text and blockquote

Step 7: Validate your HTML

📸 Verified Output:

Step 8: View in browser

Open http://localhost:8080/lab02-text.html and observe the visual difference between each text element.

📸 Verified Output:

  • Headings display in decreasing font sizes

  • <strong> and <em> apply bold/italic with semantic meaning

  • <pre> preserves whitespace formatting

✅ Verification

Count the text elements in your file:

🚨 Common Mistakes

  • Using <b> instead of <strong> — Screen readers treat these differently

  • Multiple <h1> tags — Breaks document outline for SEO and accessibility

  • Using <br> for spacing — Use CSS margin/padding instead

  • Skipping heading levels — Jump from <h1> to <h3> confuses screen readers

📝 Summary

You learned:

  • Heading hierarchy h1h6 for document structure

  • <p> for paragraphs, <br> for line breaks, <hr> for thematic breaks

  • Semantic tags: <strong>, <em>, <mark>, <del>, <ins>, <abbr>

  • Inline grouping with <span>

  • Block-level elements: <pre>, <blockquote>

🔗 Further Reading

Last updated