Home >Web Front-end >HTML Tutorial >What is the difference between class and id
What is the difference between
id and class? What does ID mean? What does class mean? Today we will introduce to you these two easily confused concepts
You can see the use of id and class in div, span, p tags, h1, h2 and other tags. id and class are very commonly used tagsAttributes.
<div id="header"></div> <div class="menu"></div>
The above is what we often see id and class existing in div tags. "Header" and "menu" are custom CSS names. (Pay attention to the case of CSS naming, and do not name css starting with a number)
Explanation on the usage of id and class
1. Differences in usage
id is unique, in a web page The same name can only be used once; a class named
class can be used countless times in a web page.
2. Difference in css
id in css code is a class named starting with "#" pound sign
class is named in css code starting with "." Class names starting with a lowercase period symbol
What do id and class mean?
Both id and class can be used in any tag on the web page. Generally, IDs are used for more important parts and special boxes, while classes are used for small parts that are not important or small structures. id calls the style selector named with the "#" pound sign in CSS, and class calls the style selector named with "." English half-width lowercase period in CSS.
I believe that through this article everyone should have a deep impression of their differences. For more exciting content, please pay attention to php Chinese website Other related articles!
Related reading:
The above is the detailed content of What is the difference between class and id. For more information, please follow other related articles on the PHP Chinese website!