Nearby lessons

4 of 19

🎯 CSS Selectors

📌 What are CSS Selectors?

CSS Selectors allow you to apply styles to specific HTML elements. They are the foundation of targeting in CSS, enabling you to control how your web content looks and behaves.

Selectors are patterns that match elements in your HTML. CSS uses them to determine which elements a set of style rules should apply to. Mastering selectors is key to writing efficient and clean CSS.

1️⃣ Element Selector

Selects all elements of a specific type such as h1, p, or div.

Example02
🎨Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

2️⃣ Grouping Selector

Applies the same styles to multiple selectors by separating them with commas.

Example03
🎨Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

3️⃣ Class Selector

Targets all elements with a specific class attribute using a dot (.).

Example04
🎨Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

4️⃣ ID Selector

Targets a specific element by its unique ID using a hash (#).

Example05
🎨Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

5️⃣ Universal Selector

Selects all elements on the page. Use sparingly, especially on large pages for performance reasons.

Example06
🎨Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5