大网数据广告活动
Web 标准与前端开发

`headingreset` HTML global attribute

· 52CE 我爱测

The **`headingreset`** global attribute stops the `headingoffset` values of ancestor elements from applying to the heading elements inside the element it is set on.

The headingreset global attribute stops the headingoffset values of ancestor elements from applying to the heading elements inside the element it is set on.

Values

This is a boolean attribute; it takes effect when it is present. A value for it is ignored, so headingreset, headingreset="", and headingreset="false" all have the same effect.

Description

When a browser computes the heading level of a heading element, it walks up the ancestor chain and adds up the headingoffset values it finds. The headingreset attribute stops that walk: offsets set on the element itself still count, but no ancestor above it contributes an offset.

Use this attribute for content that is not part of the structure of the surrounding document, such as a dialog, a popover, or markup inserted from another source. Their headings then take the level of their element name.

If the element carries both headingoffset and headingreset, its own offset applies and everything above it is discarded.

Examples

Resetting heading levels in a dialog

In this example, the <section> offsets its headings by 2, so the heading directly inside it is at level 3. The <dialog> element has headingreset, so the section's offset never reaches the heading inside the dialog, which stays at level 1:

<section headingoffset="2">
  <h1>Level 3</h1>

  <dialog headingreset>
    <h1>Level 1</h1>
    <p>The offset of the section does not apply here.</p>
  </dialog>
</section>

Using headingreset and headingoffset on the same element

In this example, the outer offset of 3 never reaches the heading. Only the offset on the element with headingreset applies, so the heading is at level 2:

<div headingoffset="3">
  <div headingreset headingoffset="1">
    <h1>Level 2</h1>
  </div>
</div>

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

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

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