Can someone please explain how this attribute is used?

What is the difference between id and class?

Why would you use id rather than class?