var base_url = '';

Creating CSS Selectors

CSS selectors are used to select the content you want to style. Selectors are the part of CSS rule set. CSS selectors select HTML elements according to its id, class, type, attribute etc.

There are several different types of selectors in CSS.

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

Element Selector

The element Selector

The element selector selects elements based on the element name.

You can select all

elements on a page like this (in this case, all

elements will be center-aligned, with a red text color):


Class Selector

The class Selector

The class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class.

In the example below, all HTML elements with class="center" will be red and center-aligned:


CSS Class Selector Example

ID Selector

The id Selector

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element should be unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

The style rule below will be applied to the HTML element with id="para1":


Grouping Selectors

Grouping Selectors

If you want have same styles on different you can use selectors like this


CSS Comments

CSS Comments

Comments are used to explain the code, and may help when you edit the source code at a later date. Comments are ignored by browsers.

A CSS comment starts with /* and ends with */. Comments can also span multiple lines:


Universal Selector

Universal Selector

The universal selector works like a wild card character, selecting all elements on a page. Every HTML page is built on content placed within HTML tags. Each set of tags represents an element on the page. Look at the following CSS example, which uses the universal selector:


Compound CSS Selectors or Descendant Combinator

Compund Selector or Descendant Combinator

The descendant selector or compound selector lets you combine two or more selectors so you can be more specific in your selection method. This type of selector has a higher priority than the other methods. 


  • #some-id .some-class has higher priority over .some-class
  • #some-id .some-class div has higher priority over .some-class div


Attribute Selector

Attribute Selector

The attribute selector targets elements based on the presence and/or value of HTML attributes, and is declared using square brackets:


Pseudo Class Selector - Hover

Pseudo Class Selector - Hover, active and Visited

A pseudo-class uses a colon character to identify a pseudo-state that an element might be in—for example, the state of being hovered, or the state of being activated. a:hover - a link when the user mouses over it

Let’s look at a common example:


CSS Selector Task 1

CSS Selector Task 2

CSS Selector Task 3

CSS Selector Task 4

CSS Selector Task 5

Contact Details

Mobile Number :
9891 222 738,
9891 50 1300

E-mail :

ADDRESS: H-17 / 263, First Floor,Sector 7,
Near Rohini West Metro Station,
Opposite Metro Pillar No. 425
Rohini, Delhi - 110085

Working hours

Day Timing
Monday To Friday 8:00 Am To 7:00Pm
Saturday 10:00 Am To 6:00Pm