Element selectors help you style all elements of a certain type on your webpage. They make it easy to change the look of headings, paragraphs, or any HTML tag all at once.
Element selectors in CSS
element {
property: value;
}The element is the HTML tag name you want to style, like p or h1.
All elements of that type on the page will get the styles inside the curly braces.
p {
color: blue;
}<h1> headings to be bigger and bold.h1 {
font-size: 2rem;
font-weight: bold;
}button {
background-color: lightgray;
border-radius: 0.5rem;
}This page styles all <p> elements with dark green text and a bigger font. The <h2> heading is styled with dark red color and a clean font. No classes or IDs are needed.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Element Selector Example</title> <style> p { color: darkgreen; font-size: 1.2rem; font-family: Arial, sans-serif; } h2 { color: darkred; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h2>Welcome to My Page</h2> <p>This paragraph is styled using an element selector.</p> <p>All paragraphs look the same without adding classes.</p> </body> </html>
Element selectors apply styles to every matching tag on the page, so use them when you want consistent styling.
They have lower priority than class or ID selectors, so more specific selectors can override them.
Use element selectors to keep your CSS simple and avoid repeating styles.
Element selectors target all HTML tags of a certain type.
They help style many elements quickly and consistently.
They are simple and useful for basic styling without extra classes.