Selecting Elements

Learn what CSS selectors are and how we can use them to style HTML elements.

We use selectors to target the HTML elements we want to style with CSS. We do this by associating declarations to elements on the web page.

The four basic selectors are:

  1. Element
  2. Class
  3. ID
  4. Universal

Element selectors

We use an element selector to select an HTML element by its name. For example, we have a paragraph of text on our HTML page, given below:

<p>My paragraph</p>

Using CSS, we can select this p element and style it however we like. For example, we may want to change the color of the text to red.

We can do this by targeting the element using the p selector. This is a simple CSS rule to achieve this would be:

Get hands-on with 1200+ tech skills courses.