<ins>: 插入文本元素

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

<ins> HTML 元素表示已添加到文档中的一段文本。您可以使用 <del> 元素以类似的方式表示已从文档中删除的一段文本。

试一试

<p>&ldquo;You're late!&rdquo;</p>
<del>
  <p>&ldquo;I apologize for the delay.&rdquo;</p>
</del>
<ins cite="../how-to-be-a-wizard.html" datetime="2018-05">
  <p>&ldquo;A wizard is never late &hellip;&rdquo;</p>
</ins>
del,
ins {
  display: block;
  text-decoration: none;
  position: relative;
}

del {
  background-color: #ffbbbb;
}

ins {
  background-color: #d4fcbc;
}

del::before,
ins::before {
  position: absolute;
  left: 0.5rem;
  font-family: monospace;
}

del::before {
  content: "−";
}

ins::before {
  content: "+";
}

p {
  margin: 0 1.8rem;
  font-family: "Georgia", serif;
  font-size: 1rem;
}

属性

此元素包含全局属性

cite

此属性定义了一个解释更改的资源的 URI,例如指向会议记录或故障排除系统中的工单的链接。

datetime

此属性指示更改的时间和日期,并且必须是一个有效的日期,可以选择性地附加一个时间字符串。如果该值无法解析为带有可选时间字符串的日期,则该元素没有关联的时间戳。有关不带时间的字符串的格式,请参阅有效日期字符串的格式。如果包含日期和时间的字符串的格式,请参阅有效本地日期和时间的格式

无障碍

在大多数屏幕阅读器技术的默认配置下,<ins> 元素的存在不会被播报。可以通过使用 CSS 的 content 属性,并结合 ::before::after 伪元素来使其被播报。

css
ins::before,
ins::after {
  clip-path: inset(100%);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

ins::before {
  content: " [insertion start] ";
}

ins::after {
  content: " [insertion end] ";
}

一些使用屏幕阅读器的用户会故意禁用那些会产生过多冗余信息的播报。因此,很重要的一点是不要滥用此技术,仅在不了解内容已被插入会严重影响理解的情况下才使用它。

示例

html
<ins>This text has been inserted</ins>

结果

技术摘要

内容类别 措辞内容流内容
允许内容 透明.
标签省略 无,起始标签和结束标签都必须存在。
允许父级 任何接受短语内容的元素。
隐式 ARIA 角色 插入
允许的 ARIA 角色 任意
DOM 接口 HTMLModElement

规范

规范
HTML
# the-ins-element

浏览器兼容性

另见

  • 用于标记文档中删除内容的 <del> 元素