View video tutorial

CSS Simple Selectors

CSS

Basic selection is based on element name, id, class.

The CSS element Selector

The element selector selects HTML elements based on element names.

Example

p {
  text-align: center;
  color: red;
}
Try it Now »

Click on the "Try it Now" button to see how it works.


The CSS id Selector

The id selector uses the hash (#) character followed by the id name of an HTML element to select a specific element.

The id name should not start with a number.

Example

#pg {
  font-style: italic;
  color: red;
}
Try it Now »

Click on the "Try it Now" button to see how it works.


The CSS class Selector

The class selector uses the dot (.) character followed by the class name of an HTML element to select a specific element.

The class name should not start with a number.

Example

.pg {
  font-style: italic;
  color: red;
}
Try it Now »

Click on the "Try it Now" button to see how it works.


Sample Code

Copy each file contents and paste it to your own project and run to see the final output