Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between the id and class attributes in HTML

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the difference between id and class attributes in HTML, the content is simple and clear, and I hope it can help you solve your doubts. Let me take you to study and learn about the difference between id and class attributes in HTML.

HTML id attribute

The id attribute is the unique identifier used to specify the document; therefore, you can use id to distinguish between different modules in the page. CSS and JavaScript use the id attribute to perform specific tasks for unique elements. In CSS, the id attribute is written using the # symbol followed by id.

Basic syntax:

In HTML:

one

In the CSS style sheet:

one

two

three

# id_name {

/ / CSS attribute

}

Example:

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

HTML id attribute

# demo {

Color:red

Font-size:25px

}

Hello World!

Welcome to!

Php from entry to proficiency, one-stop php self-learning platform!

HTML class attribute

The class attribute is used to specify one or more class names for the HTML element; the class attribute can be used for any HTML element. CSS and JavaScript can use class names to perform certain tasks for elements with specified class names. The class name in the CSS stylesheet uses "." Symbols.

Basic syntax:

In HTML:

one

In the CSS style sheet:

one

two

three

.class _ name {

/ / CSS attribute

}

Example:

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

HTML class attribute

.demo {

Color:red

Font-size:25px

}

Hello World!

Welcome to!

Description: the same class name can appear multiple times in the page, so you can repeatedly reference the same css, reducing the amount of work and code.

The above is about "what is the difference between id and class attributes in HTML". If this article is helpful and well written, please share it with your friends to learn new knowledge. if you want to know more about it, please pay more attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report