accent-color

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

accent-color CSS 属性为某些元素生成的用户界面控件设置强调色。

试一试

accent-color: red;
accent-color: #74992e;
accent-color: rgb(255 255 128);
accent-color: hsl(250 100% 34%);
<section class="default-example container" id="default-example">
  <div>
    <input checked="" id="example-element" type="checkbox" />
    <label for="example-element" id="example-label">Example Label</label>
  </div>
</section>
.container > div {
  display: flex;
  align-items: center;
}

#example-element {
  width: 40px;
  height: 40px;
}

#example-label {
  margin-left: 10px;
  font-size: x-large;
}

目前支持 accent-color 的浏览器将其应用于以下 HTML 元素

每个用户代理都有一个强调色,并带有变化以确保易读性和对比度。该强调色并非用于每个用户界面控件,也并非用于控件的每种状态。accent-color 仅适用于在其适用状态下使用强调色的用户界面控件。

语法

css
/* Keyword values */
accent-color: auto;

/* <color> values */
accent-color: darkred;
accent-color: #5729e9;
accent-color: rgb(0 200 0);
accent-color: hsl(228 4% 24%);

/* Global values */
accent-color: inherit;
accent-color: initial;
accent-color: revert;
accent-color: revert-layer;
accent-color: unset;

auto

表示由用户代理选择的颜色,如果平台有强调色,则应与平台强调色匹配。

<color>

指定用作强调色的颜色。

正式定义

初始值auto
应用于所有元素
继承性
计算值auto 按指定计算,<color> 值按 color 属性的定义计算。
动画类型按计算值类型

正式语法

accent-color = 
auto |
<color>

示例

设置自定义强调色

HTML

html
<input type="checkbox" checked />
<input type="checkbox" class="custom" checked />

CSS

css
input {
  accent-color: auto;
  display: block;
  width: 30px;
  height: 30px;
}

input.custom {
  accent-color: rebeccapurple;
}

结果

规范

规范
CSS Basic User Interface Module Level 4
# widget-accent

浏览器兼容性

另见