What is the difference between classes and IDs?

Classes refer to a whole group of elements. For example all paragraphs on the website should contain red writing. In order to do this they all have to belong to the same class. We give them a class by adding <p class = "yourClassname"> to each paragraph we want to be part of the group.
An id on the other hand can only be assigned to one certain element. E.g. you want only one paragraph on the website to have blue writing. This paragraph has it's own ID by adding <p id = "yourIDname">.
If an object has a class and an ID the ID overrides the class settings. Please make sure you never give one ID to more than one object!

MF
Answered by Milena F. HTML and CSS tutor

2027 Views

See similar HTML and CSS Mentoring tutors

Related HTML and CSS Mentoring answers

All answers ▸

Describe the advantages and disadvantages of the three main ways of adding CSS to a website


Many different data types can be stored on a computer system. Five common data types are string, Boolean, real, character and integer. Give suitable examples of data that could be held in each data type.


Show how you would give all elements that have a class of 'class1', a green background.


How would you structure a table in HTML?


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning