Skip to content
Learn Netverks

Lesson

Step 5/31 16% through track

selectors-practice

Selectors that match your HTML

Last reviewed May 28, 2026 Content v20260528
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~2 min
Level
beginner

This lesson

This lesson teaches Selectors that match your HTML—the ideas, syntax, and habits you need before moving on in HTML & CSS.

Without a solid grasp of Selectors that match your HTML, you will repeat mistakes in HTML & CSS exercises and on real pages or scripts.

You will apply Selectors that match your HTML in contexts like: Landing pages, dashboards, marketing sites, and portfolio pieces built without a framework.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

Early in the track—complete this before layout, scripting, or architecture lessons that assume these basics.

CSS selectors are how you attach rules to the nodes you actually wrote. This lesson focuses on the selectors you will use daily in combined HTML/CSS work.

High-value selectors

  • Class.card { } reusable styling hooks (preferred).
  • Typep { } good for base typography, risky for buttons/links without scoping.
  • Descendant.card p { } styles paragraphs inside cards only.
  • Child.toolbar > a { } direct children only.
  • Attributeinput[type="email"] { } for form variants.

ID selectors: use rarely

#main wins specificity wars and is hard to reuse. Prefer classes unless you truly need a unique hook (skip links, in-page anchors).

Matching practice

  1. Add class="highlight" to one list item—style only that item.
  2. Use .features li to space list items inside the features section.
  3. Try .features > li and confirm it behaves the same here (direct children).

Important interview questions and answers

  1. Q: Why are classes preferred over IDs for styling?
    A: Classes are reusable and keep specificity lower, making overrides predictable.
  2. Q: What is the difference between descendant and child combinators?
    A: Descendant matches any depth; child (`>`) matches only direct children.
  3. Q: Can one element have multiple classes?
    A: Yes—`class="card featured"`; selectors like `.card.featured` target both together.

Challenge

Style the third item only

  1. Add .features li:nth-child(3) with a distinct color.
  2. Verify it still works if you add another list item.

Done when: only the third feature is highlighted.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What part of this lesson needs a second read?
  • What would you try differently in a real project?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump