Tillitsdone
down Scroll to discover

CSS text-shadow Enhance Text with Shadows

Learn how to use the CSS text-shadow property to enhance text with shadows.

Discover available options for horizontal and vertical offsets, blur radius, and color.
thumbnail

Introduction

The CSS text-shadow property adds shadows to text, creating depth and emphasis. This property allows you to specify the horizontal and vertical positions of the shadow, the blur radius, and the shadow color. By default, there is no shadow applied to the text.

text-shadow can enhance the visual appeal of your web pages by adding subtle or dramatic shadow effects to text elements. Whether you’re looking to create a simple shadow for readability or a more complex effect for a striking design, text-shadow offers flexibility and control over the appearance of your text.

In this article, we’ll explore the syntax, values, and practical examples of the text-shadow property. We’ll also discuss browser compatibility and provide answers to frequently asked questions. By the end, you’ll have a comprehensive understanding of how to use text-shadow to elevate your web design projects.

Syntax

The text-shadow property in CSS is used to create shadow effects around text. Here’s how you can use it:

text-shadow: h-shadow v-shadow blur-radius color | none | initial | inherit;

Property Values

PropertyDescription
h-shadowDefines the horizontal position of the shadow. Negative values move the shadow to the left.
v-shadowControls the vertical position of the shadow. Negative values move the shadow upwards.
blur-radiusDetermines the blurriness of the shadow. Default is 0, meaning no blur. Optional.
noneNo shadow will be applied to the text. This is the default value.
colorSpecifies the color of the shadow. This value is optional.
initialResets the text-shadow property to its default value.
inheritInherits the value of the text-shadow property from its parent element.

Example

h1 {
text-shadow: 5px 5px 8px #00FF00;
}

In this example, the text inside the <h1> element will have a green shadow with a horizontal offset of 5px, a vertical offset of 5px, and a blur radius of 8px.

By understanding and utilizing the text-shadow property, you can add visually appealing effects to your text, making your web design more engaging and professional.

Values

The text-shadow property in CSS accepts a variety of values that allow you to customize the appearance of the text shadow. These values include horizontal and vertical offsets, blur radius, and color. Here’s a detailed breakdown of each value:

<color>

  • Description: Specifies the color of the shadow.
  • Usage: This value is optional and can be placed either before or after the offset values. If not specified, the browser will choose a default color.

<offset-x> <offset-y>

  • Description: These values specify the horizontal (<offset-x>) and vertical (<offset-y>) distances of the shadow from the text.
  • Usage:
    • <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 the blur radius.

<blur-radius>

  • Description: Determines the blurriness of the shadow.
  • Usage: This is a length value. The higher the value, the bigger the blur, making the shadow wider and lighter. If not specified, it defaults to 0.

none

  • Description: Specifies that no shadow will be applied to the text.
  • Usage: This is the default value.

initial

  • Description: Resets the text-shadow property to its default value.
  • Usage: Use this value to override any previously set shadow styles.

inherit

  • Description: Inherits the value of the text-shadow property from its parent element.
  • Usage: Use this value to ensure that the text shadow matches the parent element’s shadow.

Example Usage

h1 {
text-shadow: 2px 2px 5px #ff0000; /* Red shadow with a slight blur */
}
p {
text-shadow: none; /* No shadow */
}
span {
text-shadow: inherit; /* Inherit shadow from parent */
}

In this example:

  • The <h1> element has a red shadow with a horizontal offset of 2px, a vertical offset of 2px, and a blur radius of 5px.
  • The <p> element has no shadow applied.
  • The <span> element inherits the shadow from its parent element.

Understanding these values allows you to create a wide range of shadow effects, from subtle to dramatic, enhancing the visual appeal of your text elements.

Formal Definition

The text-shadow property in CSS is formally defined with specific initial values, applicability, inheritance, computed values, and animation types. Here’s a detailed breakdown:

PropertyValue
Initial Valuenone
Applies ToAll elements. It also applies to ::first-letter and ::first-line.
InheritedYes
Computed ValueA color plus three absolute lengths
Animation TypeA shadow list

Initial Value

  • none: By default, no shadow is applied to the text. This means that if you do not specify a text-shadow property, the text will not have any shadow effect.

Applies To

  • All elements: The text-shadow property can be applied to any HTML element that contains text.
  • ::first-letter: This pseudo-element selects the first letter of a block of text.
  • ::first-line: This pseudo-element selects the first line of a block of text.

Inherited

  • Yes: The text-shadow property is inherited from its parent element. This means that if a parent element has a text-shadow property, its child elements will also have the same shadow effect unless overridden.

Computed Value

  • A color plus three absolute lengths: The computed value of the text-shadow property includes the shadow color and three length values (horizontal offset, vertical offset, and blur radius).

Animation Type

  • A shadow list: The text-shadow property can be animated, and the animation type is a shadow list. This means that you can smoothly transition between different shadow effects using CSS animations or transitions.

Formal Syntax

The formal syntax for the text-shadow property is defined as follows:

text-shadow =
none |
[<color>? && <length>{2,3}]#;
  • none: Specifies that no shadow will be applied.
  • [<color>? && <length>{2,3}]#:
    • <color>?: An optional color value for the shadow.
    • <length>{2,3}: A set of two or three length values:
      • The first value represents the horizontal offset (<offset-x>).
      • The second value represents the vertical offset (<offset-y>).
      • The optional third value represents the blur radius.
    • #: Indicates that multiple shadows can be defined, each separated by a comma.

Understanding the formal definition of the text-shadow property helps in accurately implementing and manipulating text shadows in your web design projects. This ensures consistency and predictability in the appearance of text elements across different browsers and platforms.

Formal Syntax

The formal syntax for the text-shadow property in CSS is structured to allow for a high degree of customization. It can accept multiple shadow definitions, each specified by a combination of color, length values for offsets, and an optional blur radius. Here is the formal syntax:

text-shadow =
none |
[<color>? && <length>{2,3}]#;

Breakdown of the Syntax

  • none: Specifies that no shadow will be applied to the text. This is the default value.
  • [<color>? && <length>{2,3}]#:
    • <color>?: An optional color value for the shadow. If not specified, the browser will choose a default color.
    • <length>{2,3}: A set of two or three length values:
      • The first value represents the horizontal offset (<offset-x>).
      • The second value represents the vertical offset (<offset-y>).
      • The optional third value represents the blur radius.
    • #: Indicates that multiple shadows can be defined, each separated by a comma.

Example

Here are a few examples to illustrate the formal syntax:

/* Single shadow with color, offsets, and blur radius */
text-shadow: 2px 2px 5px #ff0000;
/* Multiple shadows */
text-shadow: 1px 1px 2px #000, 0 0 10px #fff;
/* Shadow with color and offsets, no blur radius */
text-shadow: #fc0 1px 0;
/* Shadow with offsets only, default color */
text-shadow: 5px 5px;
/* No shadow */
text-shadow: none;

Explanation

  • Single Shadow: text-shadow: 2px 2px 5px #ff0000;
    • This applies a red shadow with a horizontal offset of 2px, a vertical offset of 2px, and a blur radius of 5px.
  • Multiple Shadows: text-shadow: 1px 1px 2px #000, 0 0 10px #fff;
    • This applies two shadows. The first shadow is black with offsets of 1px and a blur radius of 2px. The second shadow is white with no offsets and a blur radius of 10px.
  • Shadow with Color and Offsets: text-shadow: #fc0 1px 0;
    • This applies a yellow shadow with a horizontal offset of 1px and no vertical offset.
  • Shadow with Offsets Only: text-shadow: 5px 5px;
    • This applies a shadow with horizontal and vertical offsets of 5px each, using the default color.
  • No Shadow: text-shadow: none;
    • This specifies that no shadow will be applied to the text.

Understanding the formal syntax of the text-shadow property allows you to create complex and visually appealing shadow effects for your text elements. By combining multiple shadows, you can achieve layered effects that add depth and dimension to your web design.

Examples

To help you understand how to use the text-shadow property in practical scenarios, let’s explore some examples. These examples cover simple shadows, multiple shadows, and more complex effects.

Simple Shadow

In this example, we apply a basic green shadow to a heading element:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Shadow</title>
<style>
h1 {
text-shadow: 5px 5px 8px #00FF00;
}
</style>
</head>
<body>
<h1>Website</h1>
</body>
</html>

Output

The heading “Website” will have a green shadow with a horizontal and vertical offset of 5px and a blur radius of 8px.

Multiple Shadows

In this example, we create a glowing text effect by applying multiple shadows to a paragraph:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Shadow</title>
<style>
h2 {
font-size: 24px;
text-shadow: 0 0 10px #FFD700,
0 0 20px #FFA500,
0 0 30px #FF6347;
color: #fff;
background-color: #333;
padding: 20px;
}
</style>
</head>
<body>
<h2>Glowing Text Effect</h2>
</body>
</html>

Output

The heading “Glowing Text Effect” will have a glowing effect with multiple shadows, creating a visually striking appearance.

Adding Multiple Shadows for Depth

In this example, we apply multiple shadows to create a layered effect, simulating depth:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Shadow with Depth</title>
<style>
h3 {
font-size: 24px;
text-shadow: 3px 3px 2px rgba(0, 0, 0, 0.5),
-3px -3px 2px rgba(255, 255, 255, 0.7);
color: #FF4500;
background-color: #f0f0f0;
padding: 10px;
}
</style>
</head>
<body>
<h3>Text Shadow with Depth</h3>
</body>
</html>

Output

The heading “Text Shadow with Depth” will have a layered shadow effect, creating a sense of depth and dimension.

Outline Text Effect

Create an outline effect with text shadows to make text stand out against a background:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Outline Text Effect</title>
<style>
.outline-text {
font-size: 30px;
color: white;
text-shadow: 2px 2px 4px black;
}
</style>
</head>
<body>
<p class="outline-text">
Outline effect with white text and shadow
</p>
</body>
</html>

Output

The text “Outline effect with white text and shadow” will have a white color with a black shadow, creating an outline effect that makes the text stand out against the background.

Glowing Text Effect with Animation

Create a glowing text effect that animates to make the text appear dynamic:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glowing Text Effect with Animation</title>
<style>
.glowing-text {
font-size: 24px;
text-shadow: 0 0 5px #ff0000, 0 0 10px #ff0000, 0 0 15px #ff0000;
color: white;
animation: glow 1s infinite alternate;
}
@keyframes glow {
from {
text-shadow: 0 0 5px #ff0000, 0 0 10px #ff0000, 0 0 15px #ff0000;
}
to {
text-shadow: 0 0 10px #ff0000, 0 0 20px #ff0000, 0 0 30px #ff0000;
}
}
</style>
</head>
<body>
<p class="glowing-text">
Glowing Text Effect with Animation
</p>
</body>
</html>

Output

The text “Glowing Text Effect with Animation” will have a glowing effect that animates, creating a dynamic appearance.

These examples demonstrate the versatility of the text-shadow property. By adjusting the offsets, blur radius, and color, you can create a wide range of shadow effects to enhance the visual appeal of your text elements.

Specifications

The text-shadow property is defined in the CSS Text Decoration Module Level 3. This module provides detailed information on how the text-shadow property should be implemented by web browsers.

CSS Text Decoration Module Level 3

WebsiteUrl

The CSS Text Decoration Module Level 3 specification defines the text-shadow property and its behavior. This module is part of the broader CSS specification and is maintained by the World Wide Web Consortium (W3C).

Understanding the specifications helps ensure that your use of the text-shadow property is consistent with the standards and works correctly across different web browsers.

Browser Compatibility

The text-shadow property is widely supported across modern web browsers. Here is a summary of its compatibility:

Browser Support

BrowserVersion
Chrome1.0
Edge4.0
Firefox3.5
Safari1.1
Opera9.5
Internet Explorer10.0

Notes

  • Internet Explorer: The text-shadow property is supported in Internet Explorer 10.0 and later.
  • Opera Mini: The text-shadow property is not supported in Opera Mini.

Example

Here is an example that shows the use of the text-shadow property with a fallback for browsers that do not support it:

h1 {
text-shadow: 5px 5px 8px #00FF00;
/* Fallback for browsers that do not support text-shadow */
background-color: #00FF00;
color: #fff;
}

In this example, the h1 element will have a green shadow with a horizontal and vertical offset of 5px and a blur radius of 8px. For browsers that do not support the text-shadow property, a green background color and white text color are used as a fallback.

By considering browser compatibility, you can ensure that your web design looks consistent and appealing across different browsers and devices.

Frequently Asked Questions

What is the text-shadow property in CSS?

The text-shadow property in CSS is used to add shadows to text elements. This property allows you to specify the horizontal and vertical positions of the shadow, the blur radius, and the shadow color. By default, no shadow is applied to the text.

How do I use the text-shadow property?

To use the text-shadow property, you can specify the horizontal and vertical offsets, the blur radius, and the color of the shadow. Here is the syntax:

text-shadow: h-shadow v-shadow blur-radius color;

For example:

h1 {
text-shadow: 5px 5px 8px #00FF00;
}

This will apply a green shadow to the h1 element with a horizontal and vertical offset of 5px and a blur radius of 8px.

Can I apply multiple shadows to a text element?

Yes, you can apply multiple shadows to a text element by separating each shadow definition with a comma. For example:

h1 {
text-shadow: 2px 2px 5px #ff0000,
4px 4px 10px #0000ff;
}

This will apply two shadows to the h1 element: a red shadow with a horizontal and vertical offset of 2px and a blur radius of 5px, and a blue shadow with a horizontal and vertical offset of 4px and a blur radius of 10px.

Is the text-shadow property supported in all browsers?

The text-shadow property is widely supported in modern web browsers, including Chrome, Edge, Firefox, Safari, and Opera. However, it is not supported in Internet Explorer versions earlier than 10.0 and is not supported in Opera Mini.

How can I ensure that my text shadow looks good across different browsers?

To ensure that your text shadow looks good across different browsers, you can provide fallback styles for browsers that do not support the text-shadow property. For example:

h1 {
text-shadow: 5px 5px 8px #00FF00;
/* Fallback for browsers that do not support text-shadow */
background-color: #00FF00;
color: #fff;
}

This will apply a green shadow to the h1 element and use a green background color and white text color as a fallback for browsers that do not support the text-shadow property.

By understanding and utilizing the text-shadow property, you can add visually appealing effects to your text, making your web design more engaging and professional.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.