HTML ID & Classes
What Is ID
- ID
-
Unique Identifier - ID Is A Unique Identifier That Can Be Given To Any One Element Like Div Or Span If You Want To Give The Same ID To Another Element So That Can't Be Done You Can Give It Another ID Like Example Below
-
The First Div Would Contain This ID <div id="firstdiv"></div>
-
The Second Div Must Contain Another ID Like This <div id="seconddiv"></div>
What Is Class
- Class
-
The class attribute lets you give the same name to multiple HTML elements. That way, you can easily change their look or behavior all at once. Classes are not unique and can be assigned to multiple elements. They are generally used for applying the same styles or behaviors to a group of elements.
-
The First Div Or Span Would Contain This Class <div class="red"></div>
<span class="red"></span>
-
The Second Div Or Span Can Contain The Same Class Or More Than 1 Class By Seperating Them With A Single Space Between Them Inside Class Attribute Like This <div class="red bg-yellow"></div>
<span class="red bg-yellow"></span>
I'm A Div With ID firstdiv And Two Classes red And bg-yellow.
I'm Another Div With ID seconddiv And One Class red.
I'm A Span With Class bg-yellow.
I'm Another Span With Same Class bg-yellow.
ID And Class Are Attributes In A Element Not An Element Themselve.
ID Also Helps In Linking Like If You Click On Given Link Below So You'll Be Redirected To ID Named lastdiv In Same Page And You Can Check It By Inspecting In Chrome Browser.
Go To Last Div
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
You Got Me I'm The Last Div In This Page
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.