CSS-Selectors- class(.) &Id(#)

Just like type selectors we have class and Id selectors in our HTML page. Let's suppose we have numerous div tags, heading tags or any other element. We would like to specify particular CSS attribute to one of those elements which is where class and ID selectors are helpful.

Here is the below syntax example for Class selectors and ID selectors.

Class selector.PNG Class selector-1 .PNG we should always represent . character before the Class Name in our stylesheet & we could name our class anything there is no naming convention for class or ID selectors.

HTML elements can also refer to more than one class. Below is the example, it has red and large as the class names.

class selector-2.PNG class selector-2-1.PNG Class selector-2-3.PNG

However, The id of an element is unique within a page, so the id selector is used to select one unique element! Below are the examples for ID Selectors. Always remember to use # character before the name in the stylesheet. Here the output is same for both class and Id selectors.

ID selector.PNG ID selector-1.PNG