Home  >  Article  >  Web Front-end  >  What is the difference between id and class in html

What is the difference between id and class in html

青灯夜游
青灯夜游Original
2021-11-18 11:19:3116773browse

Difference: 1. The scope of class is larger than that of id. ID is unique and can only be called once in a page, while class can be called multiple times; 2. ID corresponds to the style selector of CSS. is "#", and the style selector corresponding to class in CSS is "."; 3. The priority of the id selector is higher than the class selector.

What is the difference between id and class in html

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Comparison of class and id in Html:

1. The scope of effect is different:

class has a larger range than id, which represents a unique identifier, just like our personal ID card. It is unique and can only be called once on a page. Generally, a web page does not have two or more IDs. The scope of class is wider. Class is a class label and can be called multiple times in an interface. Can be reused.

2. The syntax used is different:

How the id selector is used in css, such as using div as an example: (For example, there are div respectively id='i'... and div class='c'...Two div boxes, the methods quoted in css are as follows:)

.c{
属性:属性值;
} 
#i{
属性:属性值;
}

3. Priority The levels are different:

The priority of the id selector is higher than the priority of the class selector. For more important ones, you can use the id selector.

Recommended tutorial: "html video tutorial"

The above is the detailed content of What is the difference between id and class in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn