search
HomeWeb Front-endH5 TutorialIntroduction to p and span tags in HTML5

1. Selection of ID and class

It is often difficult for us to decide whether an element should use ID or class name. Here are the summary results directly:

Only Use ID only when the target element is so unique that the term will never be used elsewhere on the site. In other words, you should only use ID if you are absolutely sure that the element will only appear once. If you think that in the future If you need similar elements, just use classes.

The summary is already very clear, so there is no need to explain too much.

Let’s talk about the respective consequences when overused. Disadvantages.

Disadvantages of using too many IDs:If you use a lot of IDs, you will soon have difficulty finding unique names, and you will end up having to create very long and complex naming conventions. Solution For this problem, you only need to read the summary above.

Disadvantages of using too many classes:Some people are used to adding a class to every place in the style when writing CSS styles, so that To control the required style more accurately. This will actually cause the code to be cumbersome and less flexible. So when we write code, if you find repeated words in the class hit, you should consider decomposing these elements into their components. section, this will greatly improve flexibility and make the page more concise. See the example below.

  <h2 id="这是头部">这是头部</h2>
  <p class="news-text">这是一个文本</p>
  <p class="news-text">这是另一个文本</p>

With repeated words like this, you should consider whether these elements can be broken down into their component parts, so that the code More "componentized". For example, write it like this:

<p class="news">
    <h2 id="这是头部">这是头部</h2>
    <p>这是一个文本</p>
    <p>这是另一个文本</p>
</p>

and then identify different contents through cascade.

2.p and span

p elements are An element that helps add structure to the document. p is not semantic, p actually stands for part (pision). Likewise, do not overuse the p element.
Be careful when using p:The p element should only be used when there is no existing element that can achieve area division. Otherwise, the code will be too complicated.
PS: I didn’t want to write an example in a book about this. But from my perspective. Just tell me this sentence. Although I know it should be like this, I don't know whether to use p at a certain moment.

If this is a mainnavigationlist. Don't defend it in p.

Emmet简写为:p>ul>li*3>a[href=#] 然后按Table键
<p>
        <ul>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
        </ul>
    </p>

But don't mechanically think that as long as it is an ul tag, it does not need to be wrapped with a p tag. Let's take a look at the content of classclass in 1. You I feel that when I want to do some style design on the labels of the entire main navigation list, should I add a class or id to each li label, or should I just add a p label to wrap it as mentioned in 1 to make the code "componentized" ".

I have never done H5 development, but I know that there is no absolute in this kind of thing. You still need to check whether to use p according to the purpose of use. I personally feel that although it is a navigation list, You can directly use ul to construct it, but I think adding a p is not just to make the navigation list a block, but also to tell me that the navigation list is a part.

The main function of the element is to group or identify the elements within the row.

<p><span class="aa">Harry Knowles</span></p>

The difference between the two is already obvious.

Probably That’s it. QAQ I feel like I can write so many things in two sentences. Anyway, I can summarize them in just two sentences, but they are all important to remember.

【Related Recommendations】

1. Free h5 online video tutorial

2. HTML5 full version manual

3. php.cn original html5 Video tutorial

The above is the detailed content of Introduction to p and span tags in HTML5. 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
Understanding H5: The Meaning and SignificanceUnderstanding H5: The Meaning and SignificanceMay 11, 2025 am 12:19 AM

H5 is HTML5, the fifth version of HTML. HTML5 improves the expressiveness and interactivity of web pages, introduces new features such as semantic tags, multimedia support, offline storage and Canvas drawing, and promotes the development of Web technology.

H5: Accessibility and Web Standards ComplianceH5: Accessibility and Web Standards ComplianceMay 10, 2025 am 12:21 AM

Accessibility and compliance with network standards are essential to the website. 1) Accessibility ensures that all users have equal access to the website, 2) Network standards follow to improve accessibility and consistency of the website, 3) Accessibility requires the use of semantic HTML, keyboard navigation, color contrast and alternative text, 4) Following these principles is not only a moral and legal requirement, but also amplifying user base.

What is the H5 tag in HTML?What is the H5 tag in HTML?May 09, 2025 am 12:11 AM

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

H5 Code: A Beginner's Guide to Web StructureH5 Code: A Beginner's Guide to Web StructureMay 08, 2025 am 12:15 AM

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

H5 Code Structure: Organizing Content for ReadabilityH5 Code Structure: Organizing Content for ReadabilityMay 07, 2025 am 12:06 AM

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

H5 vs. Older HTML Versions: A ComparisonH5 vs. Older HTML Versions: A ComparisonMay 06, 2025 am 12:09 AM

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

H5 vs. HTML5: Clarifying the Terminology and RelationshipH5 vs. HTML5: Clarifying the Terminology and RelationshipMay 05, 2025 am 12:02 AM

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

HTML5 Features: The Core of H5HTML5 Features: The Core of H5May 04, 2025 am 12:05 AM

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools