大网数据广告活动
网站运营与故障问答

Which one is the correct way to use h1 tag?

· 52CE 我爱测

In a website that provides content which is divided into parts, what is the more correct way to use the H1 tag? <div class='header'> <span>Episode 2</span> <h1 class='large'>Creative work name</h1> </div> <!-- content body --> or…

问题原文

原帖链接 · Bouh · CC BY-SA 4.0

In a website that provides content which is divided into parts, what is the more correct way to use the H1 tag?

<div class='header'>
  <span>Episode 2</span>
  <h1 class='large'>Creative work name</h1>
</div>
<!-- content body -->

or:

<div class='header'>
  <h1>Episode 2</h1>
  <span class='large'>Creative work name</span>
</div>
<!-- content body -->

已采纳解答

原帖链接 · Mike Ciffone · CC BY-SA 4.0

You're going to run into duplicate <h1> tags across other episode pages if the <h1> only includes creative work name.

Speaking of semantics, why are we using <div class="header"> when we have the <header> element?

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Ep. 2, Creative Work Name - Example.com</title>
        <meta name="description" content="">
    </head>
    <body>
    <div>
        <span class="top-of-page-section">Episode 2</span>
    <div>
    <header>
        <h1>Creative Work Name - Ep 2</h1>
        <h2 class="subhead">The one about heading tags</h2>
    </header>

    <!-- Rest of page content + video, etc -->

    <footer></footer>    
    </body>
</html>

I added a couple other nuances as well.

Edit: Put the span in a div and added a header beneath. I kept the span to retain the format of your original example in your question, though it seems redundant to me (see below for what I would do. This should resolve the comments all of this without actually seeing the page is hard.

Personally, I'd probably do this and ditch the <span> if it's not necessary:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Ep. 2, Creative Work Name - Example.com</title>
        <meta name="description" content="">
    </head>
    <body>
    <header>
        <h1>Creative Work Name - Ep 2</h1>
        <h2 class="subhead">The one about heading tags</h2>
    </header>

    <!-- Rest of page -->

    <footer></footer>    
    </body>
</html>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2021-10-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。