Basic CSS Selectors
Explore the fundamentals of CSS selectors by learning how to use type, class, and id selectors to apply styling rules to HTML elements. This lesson helps you understand how to target different elements for styling, an essential skill for designing web pages with CSS.
We'll cover the following...
Basic three CSS selectors
CSS rules can select for elements in many different ways. The three basic kinds of selectors are:
typeselectors: It is used to select HTML elements by element name.classselectors: It is used to select HTML elements by a specificclassvalue.idselectors: It is used to select an HTML element associated with a specificidvalue.
The type selector
Using a type selector is as simple as typing the name of the element:
The class selector
Using a class selector is done by placing a . followed by the name of the class value:
The id selector
Using an id selector is done by placing a # followed by the id value:
Let’s take another look at type, class, and id selectors in action to see how CSS rules are applied:
Test your understanding
Given the following HTML:
<h1 class="title">Cryptocurrency: A Brief Overview</h1>
And the following CSS:
.title {
color: blue;
}
h1 {
color: green;
}
What color will the h1 element be?
Blue