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.
Code Example
2๏ธโฃ Grouping Selector
Applies the same styles to multiple selectors by separating them with commas.
Code Example
3๏ธโฃ Class Selector
Targets all elements with a specific class attribute using a dot (.).
Code Example
4๏ธโฃ ID Selector
Targets a specific element by its unique ID using a hash (#).
Code Example
5๏ธโฃ Universal Selector
Selects all elements on the page. Use sparingly, especially on large pages for performance reasons.