CSS provides various ways to select and style HTML elements:
Element Selectors
Target elements by their HTML tag name
Class Selectors
Target elements with a specific class attribute
ID Selectors
Target a unique element with a specific ID
/* Element selector */
h1 {
color: blue;
font-size: 24px;
}
/* Class selector */
.highlight {
background-color: yellow;
}
/* ID selector */
#main-title {
text-align: center;
}
h1 {
color: blue;
font-size: 24px;
}
/* Class selector */
.highlight {
background-color: yellow;
}
/* ID selector */
#main-title {
text-align: center;
}
Visual Examples
This is an h1 element
Styled with element selector
This has a highlight class
Styled with class selector
This has the main-title ID
Styled with ID selector