<s>

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTML <s> 元素 使用删除线来渲染文本。使用 <s> 元素来表示不再相关,或者不再准确的事情。但是当表示文档编辑时,不提倡使用 <s> ;为此,提倡使用 <del><ins> 元素。

内容分类 短语内容 or 流式内容
允许的内容 短语内容
标签省略 不允许,开始标签和结束标签都不能省略。
允许的父元素 任何接受短语内容的元素
允许的 ARIA 角色 任意
DOM 接口 HTMLElement

属性

这个元素仅仅包含 全局属性

备注: 直到 Gecko1.9.2(包含),Firefox 为这个元素实现了 HTMLSpanElement 接口。

示例

xml
<s>Today's Special: Salmon</s> SOLD OUT<br>
<span style="text-decoration:line-through;">Today's Special:
  Salmon</span> SOLD OUT

结果

~~Today's Special: Salmon~~ SOLD OUT ~~Today's Special: Salmon~~ SOLD OUT

Accessibility concerns

The presence of the s element is not announced by most screen reading technology in its default configuration. It can be made to be announced by using the CSS content property, along with the ::before and ::after pseudo-elements.

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

s::before {
  content: " [start of stricken text] ";
}

s::after {
  content: " [end of stricken text] ";
}

Some people who use screen readers deliberately disable announcing content that creates extra verbosity. Because of this, it is important to not abuse this technique and only apply it in situations where not knowing content has been struck out would adversely affect understanding.

规范

Specification
HTML Standard
# the-s-element

浏览器兼容性

BCD tables only load in the browser

参见

  • <strike> 元素,另一个 <s> 元素,已经废除并且不应再用于 Web 站点。
  • <del> 元素用于代替,如果数据已经删除了。
  • CSS text-decoration-line-through 属性也用于为 <s> 元素实现前者的视觉效果。