Menu
Fundamentals
CSS Selectors
Learn how to select and style HTML elements.
1What are Selectors?
CSS selectors are used to "find" (or select) the HTML elements you want to style.
Example Code
css
/* Element Selector */
p { color: red; }
/* ID Selector */
#header { background: blue; }
/* Class Selector */
.center { text-align: center; }2Understand it in a real interface
A class selector is a useful default for reusable interface styling because several elements can share it. An element selector affects every matching tag in its scope. An ID identifies a particular element and adds stronger specificity, which can make later overrides harder to manage.
3Try it yourself
Create two paragraphs and one link. Give only one paragraph a class, then style the tag and the class separately. Inspect which declaration wins on each paragraph. Change the class name in the HTML and notice that the rule no longer matches.
Finished reading?
Mark this topic as complete to track progress.