Difference between id and class attributes in html
ID and class are attributes in HTML, they are predefined attributes meaning that they have specific meaning within HTML language. Just like any other attributes in HTML, you would write id and class in key value pair format like this:
<p id=“this paragraph”>blah</p>
<p class=“all blue paragraphs”>blah</p>
ID is like your social security number (Mr Unique)
<p id=“123121234”>My social security number is 123-12-1234</p>
Class is like your birth date (Mr IcanBeAnyone-Or-Everyone )
Birthdays are not unique however, within a country there could be more than one person with same birthday. For people, eye color, hair color, etc. are also not unique attributes. Class is just like your birthday. Let’s say the government wants to give $100 to each citizen over the age of 65, they would use everyone’s birthday to classify. Similarly, in HTML, let’s say you like to make first paragraph of every chapter bold, you would create a class and add it to first paragraphs of every chapter. You can use this class in .css files to change the fonts.
<p class=“01011995”>My birthday is 01/01/1995</p>
<p class=“01011995”>His birthday is 01/01/1995</p>
<p class=“01011995”>Her birthday is also 01/01/1995</p>
In nutshell id allows you to pinpoint a specific element in the page and class allows you to group similar elements.