<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> 元素