CSS Element Tag Selector

The CSS element tag selector is used to apply styles to all HTML elements of a specific type.

The syntax for using the element tag selector is:

</>
Copy
element {
    property: value;
}

where:

ParameterDescription
elementAny HTML element tag such as p, h1, div, etc.
propertyA CSS property (e.g., color, font-size, etc.).
valueThe value of the CSS property.

Examples

Styling Paragraphs using Element Tag Selector

In the following example, we set the text color of all <p> elements to blue.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style>
        p {
            color: blue;
        }
    </style>
</head>
<body>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
</body>
</html>

Styling Headings using Element Tag Selector

In this example, we set the font size of all <h1> elements to 24px.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style>
        h1 {
            font-size: 24px;
        }
    </style>
</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

Styling Div Elements using Element Tag Selector

In this example, we add a background color of lightgray to all <div> elements.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style>
        div {
            background-color: lightgray;
        }
    </style>
</head>
<body>
    <div>This is a div element.</div>
    <div>This is another div element.</div>
</body>
</html>