Definition and Usage
The element selector selects all elements in the document that match the specified element name.
For example, the h2 selector selects all <h2> elements in the document.
For this reason, the element selector is also referred to as a "tag name selector" or,
a "type selector," in the sense that it identifies the type of element.
Basic Example
h2 { /* Selects all <h2> elements. */
background-color: yellow;
}
span { /* Selects all <span> elements. */
background-color: darkblue;
color: white;
}
<h2>Element Name Selector</h2>
<span>This is a span with text.</span>
<p>This is a p with text.</p>
<span>This is another span with text.</span>
Element Name Selector
This is a span with text.This is a p with text.
This is another span with text.To select all elements in the document, use the * selector.
Specifications
| Specification | |
|---|---|
elementName
|
Selectors Level 4 #type-selectors |
Browser Compatibility
| Selector |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
elementName
|
1 | 12 | 1 | 1 |