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

text-decoration-color

· 52CE 我爱测

CSS 属性 **`text-decoration-color`** 用于设置文本修饰线的颜色,文本修饰线是通过 text-decoration-line 属性指定的。

CSS 属性 text-decoration-color 用于设置文本修饰线的颜色,文本修饰线是通过 text-decoration-line 属性指定的。

修饰线包括下划线、上划线、删除线和波浪线,波浪线的典型用途是标明内容拼写错误(仅举例)。被指定的颜色会作用到该属性值有效范围内的所有修饰线上。

CSS Demo: text-decoration-color

text-decoration-color: red;
text-decoration-color: #21ff21;
text-decoration-color: rgb(255, 90, 255);
text-decoration-color: hsl(70, 100%, 40%);
text-decoration-color: currentColor;
<section id="default-example">
  <p>
    I'd far rather be
    <span class="transition-all" id="example-element">happy than right</span>
    any day.
  </p>
</section>
p {
  font: 1.5em sans-serif;
}

#example-element {
  text-decoration-line: underline;
}

CSS 没有直接的机制为每种线型指定唯一的颜色,不过可以通过嵌套元素的方法来实现这种效果:用 text-decoration-line 属性为每个元素应用一种线型,再用 text-decoration-color 指定线的颜色。

语法

/* <color> values */
text-decoration-color: currentColor;
text-decoration-color: red;
text-decoration-color: #00ff00;
text-decoration-color: rgba(255, 128, 128, 0.5);
text-decoration-color: transparent;

/* Global values */
text-decoration-color: inherit;
text-decoration-color: initial;
text-decoration-color: unset;

值

  • <color>
    • : 修饰文本的线的颜色。

形式语法

示例

<p>
  This paragraph has <s>some erroneous text</s> inside it that I want to call
  attention to.
</p>
p {
  text-decoration-line: underline;
  text-decoration-color: cyan;
}

s {
  text-decoration-line: line-through;
  text-decoration-color: red;
  text-decoration-style: wavy;
}

示例

Accessibility concerns

It is important to ensure that the contrast ratio between the color of the text, the background the text is placed over, and the text decoration line is high enough that people experiencing low vision conditions will be able to read the content of the page. Color contrast ratio is determined by comparing the luminosity of the text and background color values.

Color alone should not be used to convey meaning. For example, change of text and text-decoration-color alone is not enouch to indicate a link has focus.

规范

浏览器兼容性

参见

  • 当要设置多个线修饰属性时,用 text-decoration 简写属性会比分别写多个属性更方便。
  • <color> 数据类型
  • 其他与颜色相关的属性:background-color, border-color, outline-color, text-decoration-color, text-emphasis-color, text-shadow, caret-color, 和 column-rule-color
  • 使用 CSS 为 HTML 设置颜色

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

资料来源与适用范围

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

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

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