The Wayback Machine - https://web.archive.org/web/20250108184332/https://www.geeksforgeeks.org/css-text-shadow-property/
Open In App

CSS text-shadow Property

Last Updated : 04 Jan, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The CSS text-shadow property adds shadows to text for depth and emphasis. It accepts values for horizontal and vertical shadow positions, blur radius, and shadow color. The default is no shadow is none.

Syntax

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

Property values

Here are the property values for the text-shadow CSS property:

Property Description
h-shadow Defines the horizontal position of the shadow. Negative values move the shadow to the left.
v-shadow Controls the vertical position of the shadow. Negative values move the shadow upwards.
blur-radius Determines the blurriness of the shadow. The default is 0, meaning no blur. Optional.
none No shadow will be applied to the text. This is the default value.
color Specifies the color of the shadow. This value is optional.
initial Resets the text-shadow property to its default value.
inherit Inherits the value of the text-shadow property from its parent element.

CSS text-shadow Property Examples

Example 1: Adding a Simple Shadow

In this example we applies a green text shadow to the <h1> element with a horizontal offset of 5px, vertical offset of 5px, blur radius of 8px, and color #00FF00.

HTML
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <style>
        h1 {
            text-shadow: 5px 5px 8px #00FF00;
        }
    </style>

<!--Driver Code Starts{-->
</head>
<body>
    <h1> GeeksforGeeks </h1>
</body>
</html>
<!--Driver Code Ends }-->

Output

Example 2: Creating a Glowing Text Effect

In this example we creates a glowing text effect for <h2> with multiple shadows using text-shadow, styled with contrasting background and padding for visibility.

HTML
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <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>

<!--Driver Code Starts{-->
</head>
<body>
    <h2>Glowing Text Effect</h2>
</body>
</html>
<!--Driver Code Ends }-->

Output

text-shadow

CSS text-shadow Property Example Output

Example 3: Adding Multiple Shadows for Depth

In this example, we apply multiple shadows to an <h3> element to create a layered effect, simulating depth. The shadows are offset in different directions and colors.

HTML
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <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>

<!--Driver Code Starts{-->
</head>
<body>
    <h3>Text Shadow with Depth</h3>
</body>
</html>
<!--Driver Code Ends }-->

Output

 Adding Multiple Shadows for Depth output

CSS text-shadow Property

CSS text-shadow Property – FAQs

How do you create glowing text effects with CSS?

You can create glowing text by using multiple layers of shadows with bright colors and varying blur radii, making the text appear like it’s emitting light.

What makes text-shadow different from box-shadow?

While text-shadow applies shadow effects to text, box-shadow creates shadows around the entire element’s box, such as divs or buttons.

Can you add multiple shadows to text in CSS?

Yes! You can stack multiple shadows on text by separating each shadow value with a comma, allowing you to create layered or glowing effects.

Can text-shadow be applied to any font type?

Absolutely! The text-shadow property works with all font types and sizes, offering flexibility in design.

Is it possible to create an inner shadow for text?

No, text-shadow in CSS only supports outer shadows. However, you can create inner shadows for box elements using the box-shadow property.



Next Article

Similar Reads

three90RightbarBannerImg