CSS Text Shadow
The CSS text-shadow property allows you to add shadow effects to text, enhancing the visual appearance. It helps in making text stand out by adding depth and style. You can specify the shadow's horizontal and vertical offsets, blur radius, and color.
Key Points on CSS Text Shadow:
- The
text-shadow
property adds shadow to text elements. - You can define multiple shadows for an element by separating them with commas.
- The syntax of the text-shadow property is
horizontal-offset vertical-offset blur-radius color
. - The
blur-radius
is optional and adds a blur effect to the shadow. - Shadows can be applied to any text, such as headings, paragraphs, or links.
- Text shadow effects are often used for decorative purposes or to improve text readability against complex backgrounds.
Syntax for CSS Text Shadow:
Syntax Example
/* Syntax for text-shadow */
text-shadow: horizontal-offset vertical-offset blur-radius color;
/* Example */
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
Examples of CSS Text Shadow:
The following examples demonstrate the usage of text-shadow property:
Code Example: Basic Text Shadow
h1 {
text-shadow: 2px 2px 3px #000;
}
Output
This heading has a simple text shadow.
Code Example: Multiple Text Shadows
h2 {
text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.3), 4px 4px 6px rgba(0, 0, 0, 0.2);
}
Output
This heading has multiple text shadows.
Code Example: Glowing Text Shadow
p {
text-shadow: 0 0 10px #ff0000, 0 0 20px #ff0000;
}
Output
This paragraph has a glowing text shadow effect.
Common Properties of CSS Text Shadow:
- horizontal-offset: Defines the horizontal distance of the shadow from the text.
- vertical-offset: Defines the vertical distance of the shadow from the text.
- blur-radius: Controls how blurry the shadow should be (optional).
- color: Specifies the color of the shadow.
To make the text-shadow effect more appealing, consider using subtle shadows for text readability or combining different colors for creative designs. Avoid using too many layers of shadows as it can clutter the design.