text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations . Each shadow is described by some combination of X and Y offsets from the element, blur radius, and color.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

句法

/* offset-x | offset-y | blur-radius | color */
text-shadow: 1px 1px 2px black;
/* color | offset-x | offset-y | blur-radius */
text-shadow: #fc0 1px 0 10px;
/* offset-x | offset-y | color */
text-shadow: 5px 5px #558abb;
/* color | offset-x | offset-y */
text-shadow: white 2px 5px;
/* offset-x | offset-y
/* Use defaults for color and blur-radius */
text-shadow: 5px 10px;
/* Global values */
text-shadow: inherit;
text-shadow: initial;
text-shadow: unset;
					

This property is specified as a comma-separated list of shadows.

Each shadow is specified as two or three <length> values, followed optionally by a <color> value. The first two <length> values are the <offset-x> and <offset-y> values. The third, optional, <length> value is the <blur-radius> <color> value is the shadow's color.

When more than one shadow is given, shadows are applied front-to-back, with the first-specified shadow on top.

This property applies to both ::first-line and ::first-letter pseudo-elements .

<color>

Optional. The color of the shadow. It can be specified either before or after the offset values. If unspecified, the color's value is left up to the user agent, so when consistency across browsers is desired you should define it explicitly.

<offset-x> <offset-y>
Required. These <length> values specify the shadow's distance from the text. <offset-x> specifies the horizontal distance; a negative value places the shadow to the left of the text. <offset-y> specifies the vertical distance; a negative value places the shadow above the text. If both values are 0 , the shadow is placed directly behind the text, although it may be partly visible due to the effect of <blur-radius> .
<blur-radius>
Optional. This is a <length> value. The higher the value, the bigger the blur; the shadow becomes wider and lighter. If not specified, it defaults to 0 .

形式定义

初始值 none
适用于 所有元素。它还适用于 ::first-letter and ::first-line .
继承 yes
计算值 a color plus three absolute lengths
动画类型 a shadow list

形式句法

none | <shadow-t>#

where
<shadow-t> = [ <length>{2,3} && <color>? ]

where
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>

where
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
<hsl()> = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )
<hsla()> = hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )

where
<alpha-value> = <number> | <percentage>
<hue> = <number> | <angle>

范例

Simple shadow

.red-text-shadow {
  text-shadow: red 0 -2px;
}
					
<p class="red-text-shadow">Sed ut perspiciatis unde omnis iste
    natus error sit voluptatem accusantium doloremque laudantium,
    totam rem aperiam, eaque ipsa quae ab illo inventore.</p>
					

Multiple shadows

.white-text-with-blue-shadow {
  text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
  color: white;
  font: 1.5em Georgia, serif;
}
					
<p class="white-text-with-blue-shadow">Sed ut perspiciatis unde omnis iste
    natus error sit voluptatem accusantium doloremque laudantium,
    totam rem aperiam, eaque ipsa quae ab illo inventore.</p>
					

规范

规范 状态 注释
CSS Text Decoration Module Level 3
The definition of 'text-shadow' in that specification.
候选推荐 The CSS property text-shadow was improperly defined in CSS2 and dropped in CSS2 (Level 1). The CSS Text Module Level 3 spec refined the syntax. Later it was moved to CSS Text Decoration Module Level 3 .

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
text-shadow Chrome 完整支持 2 Edge 完整支持 12 Firefox 完整支持 3.5 注意事项
完整支持 3.5 注意事项
注意事项 Firefox versions before 57 have a bug whereby transition s will not work when transitioning from a text-shadow with a color specified to a text-shadow without a color specified ( bug 726550 ).
注意事项 From Firefox 4, the blur radius is capped at 300 for performance reasons.
注意事项 Firefox theoretically supports infinite text-shadows (don't try it).
注意事项 <color> value is unspecified, then Firefox uses the value of the element's color 特性。
IE 完整支持 10 Opera 完整支持 9.5 注意事项
完整支持 9.5 注意事项
注意事项 Opera supports a maximum of 6-9 text-shadows for performance reasons. The blur radius is limited to 100px.
注意事项 Opera 9.5 to 10.1 adheres to the old, reverse painting order (in CSS2, the first specified shadow is on the bottom).
Safari 完整支持 1.1 注意事项
完整支持 1.1 注意事项
注意事项 In Safari, any shadows that do not explicitly specify a color are transparent.
注意事项 Safari 1.1 to 3.2 only supports one text-shadow (displays the first shadow of a comma-separated list and ignores the rest). Safari 4.0 (WebKit 528) and later support multiple text-shadows.
WebView Android 完整支持 37 Chrome Android 完整支持 18 Firefox Android 完整支持 4 注意事项
完整支持 4 注意事项
注意事项 Firefox versions before 57 have a bug whereby transition s will not work when transitioning from a text-shadow with a color specified to a text-shadow without a color specified ( bug 726550 ).
注意事项 From Firefox 4, the blur radius is capped at 300 for performance reasons.
注意事项 Firefox theoretically supports infinite text-shadows (don't try it).
注意事项 <color> value is unspecified, then Firefox uses the value of the element's color 特性。
Opera Android 完整支持 14 Safari iOS 完整支持 1 注意事项
完整支持 1 注意事项
注意事项 In Safari, any shadows that do not explicitly specify a color are transparent.
注意事项 Safari iOS 1 and 2 only support one text-shadow (displays the first shadow of a comma-separated list and ignores the rest). Safari iOS 3 (WebKit 528) and later support multiple text-shadows.
Samsung Internet Android 完整支持 1.0

图例

完整支持

完整支持

见实现注意事项。

见实现注意事项。

Quantum CSS notes

  • Gecko has a bug whereby transition s will not work when transitioning from a text-shadow with a color specified to a text-shadow without a color specified ( bug 726550 ). This has been fixed in Firefox's new parallel CSS engine (also known as Quantum CSS or Stylo , planned for release in Firefox 57).

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Text Decoration
  4. 特性
    1. text-decoration
    2. text-decoration-color
    3. text-decoration-line
    4. text-decoration-skip
    5. text-decoration-skip-ink
    6. text-decoration-style
    7. text-decoration-thickness
    8. text-emphasis
    9. text-emphasis-color
    10. text-emphasis-position
    11. text-emphasis-style
    12. text-shadow
    13. text-underline-offset
    14. text-underline-position

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1