tutorialstonight logo
A Platform To Learn To Code

CSS CLASS SELECTOR



The CSS classes allow us to define multiple CSS properties for a specific class and when that class is added to any element then all the specified CSS property is reflected in the HTML element.

Classes are defined either in the head section within the style tag or in the external stylesheet.

Once a class is defined it can be used as many times you want to use.


Defining a class

A class defined by a class_name preceded by a dot (".") .

Syntax:

.class_name { property: value; }

Defining class in head section:

Example

Defining classes in external stylesheet.

Example


Adding class to the element

A class is added to an element using class attribute. Like shown below.

Example

Multiple classes can be added to an element. like shown below.

Example

A working example for CSS class.

Example

Run the code

Output:

This paragraph is added with class1.

This paragraph is added with class1.

This paragraph is added with class1.