此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

color

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

color 属性用来为 fill 属性、stroke 属性、stop-color 属性、flood-color 属性和 lighting-color 属性提供一个潜在的间接值(currentColor)。

作为一个外观属性,它还可以直接用作 CSS 样式表的属性。请阅读 CSS color 以了解更多信息。

使用说明

类别 外观属性
<color> | inherit

示例

html
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g color="green">
    <rect width="50" height="50" fill="currentColor" />
    <circle
      r="25"
      cx="70"
      cy="70"
      stroke="currentColor"
      fill="none"
      stroke-width="5" />
  </g>
</svg>

元素

下列元素可以使用color属性:

规范

Specification
CSS Color Module Level 4
# the-color-property
Scalable Vector Graphics (SVG) 2
# ColorProperty

浏览器兼容性