HTML/CSS

What are the best practices associated with using classes vs. ids?


1. Calling Name

When calling a class, put a full stop(.) in front of the class name. When importing an ID, a # sign is placed in front of the ID value. The following is an example of a tag with both an id value and a class name, decorated using css.



2. Duplicate Use

Classes can be used as duplicate, so the same class name can be used anywhere on the page. However, duplicate IDs cannot be used. An ID can only be used once on a page.



3. Limitation of Class & ID of an Element

In the case of a class, multiple class names can be applied to one element. However, only one ID can be applied to an element.