elibraryportal Logo

CSS Selectors

CSS selectors define on the HTML elements according to , id, class, type, attribute etc.

There are different types of selectors in CSS that is.

  1. CSS Class Selector
  2. CSS Id Selector
  3. CSS Element Selector
  4. CSS Universal Selector
  5. CSS Group Selector

1) Class Selector

Class Selector are used to full stop symbol (.)

Selects the elements that have the given class attribute.

Syntax:-

Example1:-

Test it Now

Output:

This heading, red Color.

This paragraph, blue Color.


2) Id Selector

Id Selector are used to hash character (#) symbol .

Selects an HTML element based on the value of its id attribute

Syntax:-

Example2:-

Test it Now

Output:

This heading, red Color.

This paragraph, blue Color.


3) Element Selector

Element selector selects the HTML element by the name.

Syntax:-

Example3:-

Example:-

Test it Now

4) Universal Selector

Universal selector are used to a wildcard character (*). It selects all the HTML elements on the pages.

Test it Now

Output:

HTML

CSS

JavaScript

PHP


5) Group Selector

Grouping selector is used to select all the HTML elements with the same style. Group Selector are used to Commas, separate each selector in grouping..

Test it Now

Output:

Hello HTML

Hello CSS

Bootstrap.

Next TopicHow to USe CSS