⭐ CSS Selectors with Examples⭐

Learn CSS selectors in a very easy way with examples and implement into your project. Happy Learning

CSS selectors are used for selecting the elements which you want to style. These selectors are broadly classified into multiple categories:

  1. Basic selectors
  2. Grouping selectors
  3. Combination selectors
  4. Pseudo selectors

Basic Selectors

Universal selectors The universal selector (*) selects all HTML elements on the page.

image.png

Type selectors This type of selector is used to match the elements by their node name.

image.png

Class selectors This type of selector is used to select the element with the given class name.

image.png

Id selectors This type of selector is used to select the element based on the value of its id attribute.

image.png

Attribute selectors The CSS attribute selector matches elements based on the presence or value of a given attribute.

image.png

Grouping Selectors

The grouping selector selects all the HTML elements with the same style definitions.

image.png

Combination Selectors

There are different types of combination selectors like +, >, " ",~, and many more.

image.png

Pseudo Selectors

Pseudo Selectors consist of pseudo-elements and pseudo-classes.

The simple difference between the two is that pseudo-elements (::) are used to style a specific part of an element whereas pseudo-class (:) is used to style a complete element.

Pseudo Elements

There are many pseudo elements but we are discussing most commonly used elements.
Syntax:

selection::psudo-element{
      property:value;
}

image.png

Pseudo Classes

image.png