CSS Selector
Addition to adding CSS to HTML elments like paragraph, it can also be added to Id Selectors and Class Selectors.
The three types of CSS Selectors are,
- Id Selector
- Class Selector
- HTML Element Selector
Id Selector
First of all what is an Id?
Id is a property of HTML elements which you can specify like shown below.
<p id="para1">This is a Paragraph.</p>
You can use the specified Id to manipulate the corresponding HTML Element like shown below.
The above style is applied to the HTML element with Id "para1".
"#" symbol is used to specify Id
Class Selector
Class is a property of HTML elements which you can specify like shown below.
<p class="class1">This is a Paragraph.</p> <h4 class="class1">This is a Heading.</h4> <p>This is a Paragraph without class.</p> <h4>This is a Heading without class.</h4>
The difference between class and id is that Class is used to apply styles to a group of HTML element while Id is used to apply styles for a single unique HTML element.
Styles are applied to classes like shown below.
The above style is applied to the HTML elements with class "class1".
"." symbol is used to specify class.
HTML Element Selector
Styles are applied to HTML elements without "#" or "." like shown below.
The above style is applied to the HTML element "Paragraph".