search
HomeWeb Front-endFront-end Q&AWhat are the semantic tags in html5

html5 semantic tags: 1. header tag; 2. nav tag; 3. footer tag; 4. hgroup tag; 5. section tag; 6. article tag; 7. aside tag; 8. figure tag ; 9. time tag; 10. address tag.

What are the semantic tags in html5

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

HTML semantics:

Each HTML tag has its own specific meaning (semantics), semantics refers to Use semantically appropriate tags so that the page has a good structure, and the pageelements have meaning, making it easy for both people and search engines to understand.

I have seen a more vivid example:

When building a house, bricks should be used in some places, ceramic tiles should be used in some parts, and The places must be covered with cement, so that the house will be strong, neat and beautiful.

If you insist on replacing bricks with ceramic tiles, you can barely build a house. However, such a house is not strong, easy to collapse, and the appearance is not good-looking.

Similarly, many things in life are similar! Use whatever tag should be used to represent . It has a good structure and is easier for people and search engines to understand. Another point is that it is easy to develop and maintain. I have seen a lot of web page structures, and I want to complain about them. It’s all confusing. Just leave the appearance of the task to css. Don’t lay out the layout for the sake of appearance. !

The meaning and role of semantics

  • When the style is removed or lost, the page can present a clear structure
  • User experience: For example, title and alt are used to explain nouns or explain picture information, and the flexible use of label tags;
  • is beneficial to SEO: and Search engines establish good communication to help crawlers crawl more effective information: crawlers rely on tags to determine the context and weight of each keyword;
  • facilitates other devices to parse (such as Screen readers, blind readers, mobile devices) render web pages in a meaningful way;
  • is easier for the team to develop and maintain, and semantics are more readable, which is the next step for web pages Important trends, teams that follow W3C standards all follow this standard, which can reduce differentiation.

What should we pay attention to in semantics?

  • Use as few unsemantic p and span tags as possible; use more strong semantic tags newly added in HTML5;

  • Do not use stylized tags, such as font, b, ..., etc., you can completely use css to implement styles (besides, such "stylized tags" are basically abolished in HTML5!)

  • Emphasis on the text, try to use the strong tag to strengthen the emphasis, and set the em tag in italics

  • Form writing specifications: Title Use caption, The header is surrounded by thead, the body part is surrounded by tbody, and the tail is surrounded by tfoot. Table headers and general cells should be distinguished. Use th for table headers and td for cells;

  • Form fields must use fieldset tags Wrap it up and use the legend tag to explain the purpose of the form; (To be honest, I really didn’t notice this much!)

  • The description text corresponding to each input tag needs to be used label label , and is associated with the corresponding input through the id attribute.

HTML5 semantic tags:

1.header: The tag defines the header of the "web page" or "section".

Usually contains h1-h6 elements or hgroup, as the entire page or the title of a content block. You can also wrap the table of contents part of a section, a search box, a nav, or any related logo.

<header>
     <h1 id="毕业生实习">毕业生实习</h1>
     <span>2016/08/05</span>
</header>
<!--之前使用的是无语义的div+class-->
<div class=&#39;header&#39;>...</div>

or

<header>
    <hgroup>
        <h1 id="网站标题">网站标题</h1>
        <h2 id="网站副标题">网站副标题</h2>
    </hgroup>
</header>

Usage:

  • can be the header part of "web page" or any "section";
  • has no number limit.
  • If hgroup or h1-h6 can work well by themselves, then don't use headers.

2.nav: defines the part of the navigation link.

<nav>
    <ul>
        <li><a href="#">首页</a></li>
        <li><a href="#">xxx</a></li>
        <li><a href="#">xxx</a></li>
        <li><a href="#">xxx</a></li>
    </ul>
</nav>
<!--之前使用的是无语义的div+class-->
<div class=&#39;nav&#39;>...</div>

Usage:

  • Use it on the entire pagemain navigation part. If it is not appropriate, do not use the nav element;
  • Link groups that can be used for page navigation, Not all link groups need to be placed in nav elements, Only the main and basic link groups need to be placed in it ;

##Note: For example, there will be a set of links in the footer, including terms of service, home page, copyright statement, etc., Using the footer element is most appropriate.

Specific uses: traditional navigation bar, sidebar navigation, industry navigation, page turning operations, etc.


##3.footer tag: represents "webpage" or "section" footer.

通常含有该节的一些基本信息,譬如:作者,相关文档链接,版权资料。

如果footer元素包含了整个节,那么它们就代表附录,索引,提拔,许可协议,标签,类别等一些其他类似信息。

<footer>
  作者:xxxx <br />
 Copyright © xxx.All rights reserved.
</footer>
<!--之前使用的是无语义的div+class-->
<div class=&#39;footer&#39;>...</div>

用法:

  • 可以是“网页”或任意“section”的底部部分;
  • 没有个数限制,除了包裹的内容不一样,其他跟header类似。
  • 多用于包含服务条款,友情链接、作者信息、版权信息等

4. hgroup元素:“网页”或“section”的标题

当元素有多个层级时,该元素可以将h1到h6元素放在其内,譬如文章的主标题和副标题的组合

<hgroup>
    <h1 id="主标题">主标题</h1>
    <h2 id="HTML-nbsp">HTML 5</h2>
</hgroup>

用法:

  • 如果只需要一个h1-h6标签就不用hgroup
  • 如果有连续多个h1-h6标签就用hgroup
  • 如果有连续多个标题和其他文章数据,h1-h6标签就用hgroup包住,和其他文章元数据一起放入header标签

5.section标签:定义文档中含有标题和段落的区域。(强调分段或分块)

<section>
  <h1 id="section要包含标题">section要包含标题</h1>
  <p>section要包含内容...</p>
</section>

用法:

  • article、nav、aside可以理解为特殊的section,所以如果可以用article、nav、aside就不要用section,没实际意义的就用p
  • 当容器需要标题和内容时建议使用section标签,若只是普通的容器,应该用p元素较好!section标签非p!

6.article:代表独立、完整、可独自被外部引用的内容(博客或报刊中的文章、一遍论坛帖子、一段用户评论或独立的插件、或任何独立的内容);(强调的是独立性!可含有完整的标题、内容、脚注)

<article>
   <header>
     <h1 id="标题处">标题处</h1>
   </header>
   <p>内容描述</p>
   <footer>脚部声明标注</footer>
</article>

用法:定义一个独立完整的内容部分(可包含标题,内容,脚注)时使用!

article、section间的相互嵌套关系:
拜读博文:http://www.html5jscss.com/html5-semantics-section.html


7. aside标签:表示当前页面或文章的附属信息部分,可包含于当前页面或主要内容相关的引用、侧边栏、广告、导航条、以及其他类似的有别于主要内容的部分。

书籍中的定义很长很绕,在收集之后,发现主要有两种用法:(啃下概念)

1.用于article标签之内,此时表示的是该独立内容的附属信息部分

<article>
        <p>article内容区</p>
        <aside>
            <span>附属信息1</span>
            <span>附属信息2</span>
            <span>附属信息3</span>
        </aside>
    </article>

2.用于article标签之外,此时作为页面或站点全局的附属信息部分

    <aside>
        <h1 id="附属信息标题">附属信息标题</h1>
        <a href="#">附属信息...</a>
        <a href="#">附属信息...</a>
        <a href="#">附属信息...</a>
    </aside>

用法:

  • aside在article内表示主要内容的附属信息
  • article之外则可做侧边栏,页面或站点全局的附属信息部分
  • 如果是广告,其他日志链接或者其他分类导航也可以用

(一句话概括:不同的位置表示为对应区域的附属信息!


8. figure标签:规定独立的流内容(图像、图表、照片、代码等等)。

figcaption标签:用于元素定义figure的标题。

1.一个figure元素内最多只允许放置一个figcaption元素,其他元素可无限放置。

2.figcaption 元素应该被置于 figure元素的第一个或最后一个子元素的位置。

    <figure>
        <figcaption>figure的标题</figcaption>
        <img src="/static/imghwm/default1.png"  data-src="pic.jpg"  class="lazy"   alt="...">
    </figure>

9. time标签:定义时间或日期

<p>定义时间...<time>9:00</time></p>

<p>结合datetime属性定义日期...<time datetime="2016-08-08">时间</time></p>

以上为实践操作中可能会用到的标签,HTML5还新增了很多标签,但因为用途与浏览器兼容性问题,还是为人所慎用的!待拓展!


10. address标签:代表区块容器,必须是作为联系信息出现,邮编地址、邮件地址等等,一般出现在footer。

表示文档文章作者/拥有者的联系信息,在body标签中表示文档的作者的联系信息;在article标签中表示文章作者的联系信息;

W3School示例文档:http://www.w3school.com.cn/tags/tag_address.asp

用法:

  • 标签不应该用于描述通讯地址,除非它是联系信息的一部分。
  • 元素通常连同其他信息被包含在 footer 元素中。

总结:掌握语义化含义、作用以及应当注意的细节,HTML5中常用的语义化新标签!知识点不在于多,而研究透彻应学以致用!

推荐教程:《html视频教程

The above is the detailed content of What are the semantic 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
React: The Foundation for Modern Frontend DevelopmentReact: The Foundation for Modern Frontend DevelopmentApr 19, 2025 am 12:23 AM

React is a JavaScript library for building modern front-end applications. 1. It uses componentized and virtual DOM to optimize performance. 2. Components use JSX to define, state and attributes to manage data. 3. Hooks simplify life cycle management. 4. Use ContextAPI to manage global status. 5. Common errors require debugging status updates and life cycles. 6. Optimization techniques include Memoization, code splitting and virtual scrolling.

The Future of React: Trends and Innovations in Web DevelopmentThe Future of React: Trends and Innovations in Web DevelopmentApr 19, 2025 am 12:22 AM

React's future will focus on the ultimate in component development, performance optimization and deep integration with other technology stacks. 1) React will further simplify the creation and management of components and promote the ultimate in component development. 2) Performance optimization will become the focus, especially in large applications. 3) React will be deeply integrated with technologies such as GraphQL and TypeScript to improve the development experience.

React: A Powerful Tool for Building UI ComponentsReact: A Powerful Tool for Building UI ComponentsApr 19, 2025 am 12:22 AM

React is a JavaScript library for building user interfaces. Its core idea is to build UI through componentization. 1. Components are the basic unit of React, encapsulating UI logic and styles. 2. Virtual DOM and state management are the key to component work, and state is updated through setState. 3. The life cycle includes three stages: mount, update and uninstall. The performance can be optimized using reasonably. 4. Use useState and ContextAPI to manage state, improve component reusability and global state management. 5. Common errors include improper status updates and performance issues, which can be debugged through ReactDevTools. 6. Performance optimization suggestions include using memo, avoiding unnecessary re-rendering, and using us

Using React with HTML: Rendering Components and DataUsing React with HTML: Rendering Components and DataApr 19, 2025 am 12:19 AM

Using HTML to render components and data in React can be achieved through the following steps: Using JSX syntax: React uses JSX syntax to embed HTML structures into JavaScript code, and operates the DOM after compilation. Components are combined with HTML: React components pass data through props and dynamically generate HTML content, such as. Data flow management: React's data flow is one-way, passed from the parent component to the child component, ensuring that the data flow is controllable, such as App components passing name to Greeting. Basic usage example: Use map function to render a list, you need to add a key attribute, such as rendering a fruit list. Advanced usage example: Use the useState hook to manage state and implement dynamics

React's Purpose: Building Single-Page Applications (SPAs)React's Purpose: Building Single-Page Applications (SPAs)Apr 19, 2025 am 12:06 AM

React is the preferred tool for building single-page applications (SPAs) because it provides efficient and flexible ways to build user interfaces. 1) Component development: Split complex UI into independent and reusable parts to improve maintainability and reusability. 2) Virtual DOM: Optimize rendering performance by comparing the differences between virtual DOM and actual DOM. 3) State management: manage data flow through state and attributes to ensure data consistency and predictability.

React: The Power of a JavaScript Library for Web DevelopmentReact: The Power of a JavaScript Library for Web DevelopmentApr 18, 2025 am 12:25 AM

React is a JavaScript library developed by Meta for building user interfaces, with its core being component development and virtual DOM technology. 1. Component and state management: React manages state through components (functions or classes) and Hooks (such as useState), improving code reusability and maintenance. 2. Virtual DOM and performance optimization: Through virtual DOM, React efficiently updates the real DOM to improve performance. 3. Life cycle and Hooks: Hooks (such as useEffect) allow function components to manage life cycles and perform side-effect operations. 4. Usage example: From basic HelloWorld components to advanced global state management (useContext and

React's Ecosystem: Libraries, Tools, and Best PracticesReact's Ecosystem: Libraries, Tools, and Best PracticesApr 18, 2025 am 12:23 AM

The React ecosystem includes state management libraries (such as Redux), routing libraries (such as ReactRouter), UI component libraries (such as Material-UI), testing tools (such as Jest), and building tools (such as Webpack). These tools work together to help developers develop and maintain applications efficiently, improve code quality and development efficiency.

React and Frontend Development: A Comprehensive OverviewReact and Frontend Development: A Comprehensive OverviewApr 18, 2025 am 12:23 AM

React is a JavaScript library developed by Facebook for building user interfaces. 1. It adopts componentized and virtual DOM technology to improve the efficiency and performance of UI development. 2. The core concepts of React include componentization, state management (such as useState and useEffect) and the working principle of virtual DOM. 3. In practical applications, React supports from basic component rendering to advanced asynchronous data processing. 4. Common errors such as forgetting to add key attributes or incorrect status updates can be debugged through ReactDevTools and logs. 5. Performance optimization and best practices include using React.memo, code segmentation and keeping code readable and maintaining dependability

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use