CSS element Selector

CSS element selector selects all the elements with the specified element name. CSS styles written under the element selector affect each and every element that matches the specified element name.

In the example below, the element selector selects all the <p> elements on the page and applies the same styles to each of them. Try it out to see how it works:

Example:

p{
    background: yellow;
    border: 2px solid blue;
    padding: 5px;
}

In the example below, the element selector selects all the <div> elements and applies a yellow background to each of them. Try it out:

Example:

div{
    background: yellow;
}

CSS Element Selector Syntax

The element selector has the following syntax:

element{
    CSS styles
}

Related Pages

CSS Tutorial: CSS Selectors

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts