๐Ÿš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
๐ŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Basic Selectors

Target elements with precision. Learn how to use Tag, Class, and ID selectors.

style.css
/* Type Selector */
button {
color: white;
}
/* Class Selector */
.btn-primary {
background: blue;
}
style.css
1 / 8
๐ŸŽจ

Tutor:Selectors are the pattern matching language of CSS. They tell the browser which HTML elements to style.


CSS Selector Tree

Unlock nodes by mastering targeting techniques.

Concept 1: Type Selectors

The most basic selector. It selects all elements of a given HTML tag type.

System Check

Which CSS rule makes all paragraphs blue?


Community Styles

Share Your Snippets

Created a cool selector combination? Share your CSS tricks.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Basic Selectors

Author

Pascual Vila

Frontend Instructor.

CSS Selectors are the core of Cascading Style Sheets. They allow you to target specific HTML elements on your web page and apply styles to them. Understanding the basic selectorsโ€”Universal, Type, Class, and IDโ€”is the first step to mastering CSS layout and design.

1. Universal Selector (*)

The universal selector matches every single element on the page. It is denoted by an asterisk *. It is often used for resetting margins and padding, but should be used sparingly for complex properties due to performance implications.

2. Type Selector (Element)

The type selector matches elements by their node name (tag name). For example, p selects all paragraph elements, and h1 selects all level 1 headings. This is useful for setting site-wide defaults.

3. Class Selector (.)

The class selector matches elements that have a specific class attribute. It is denoted by a dot . followed by the class name (e.g., .button). Classes are reusable, meaning you can use the same class on multiple elements.

4. ID Selector (#)

The ID selector matches an element based on the value of its id attribute. It is denoted by a hash # followed by the ID name (e.g., #header). IDs must be unique per page; only one element can have a specific ID.

Selector Glossary

* (Universal Selector)
Selects all elements in the document.
.classname (Class Selector)
Selects all elements that have the given class attribute. High reusability.
#idname (ID Selector)
Selects the single element with the specific ID. High specificity.
element (Type Selector)
Selects all elements of the given tag name (e.g., div, p, span).