CSS Shadow Effects


plant

Shadows

With CSS you can create shadow effects!

Hover over me!

CSS Shadow Effects

You can use CSS to make text and elements look like they have shadows.

In these sections, you will find details about the following attributes:

.

  • text-shadow
  • box-shadow

CSS Text Shadow

The HTML property known as text-shadow creates a shadow effect for text.

In its simplest form, you only need to specify the width (2px) for the shadow's horizontal part and the height (2px) for the shadow's vertical part within the HTML tags.

Text shadow effect!

Next, give the shadow a color:

Text shadow effect!

Next, apply a fuzzy appearance to the shadow by adding a blur effect.

Text shadow effect!

In this example, you'll notice text that's colored white and has a dark black shadow.

Text shadow effect!

This sample demonstrates a glowing red shadow that resembles neon lighting.

Text shadow effect!


Multiple Shadows

You can create several shadows for text by separating them using commas.

Here's an example that shows a shadow that looks like neon lighting in two colors: red and blue.

Text shadow effect!

In this example, you'll see white text with shadows in black, blue, and dark blue. The shadows add different colors to the text.

Text shadow effect!

You can employ the text-shadow property to create a basic text border without adding any shadows.

Border around text!


CSS box-shadow Property

The CSS property called box-shadow is utilized to add shadows to an element. This can include one or more shadows as desired.


Specify a Horizontal and a Vertical Shadow

For basic use, just mention a horizontal and a vertical shadow. The default shadow color is the same as the current text color.

A <div> element with a box-shadow

Specify a Color for the Shadow

The color attribute specifies the shadow's color.

<div> element with a lightblue box-shadow

Add a Blur Effect to the Shadow

The blur setting determines how blurry the shadow is. A larger value results in a more blurred shadow.

<div> element with a 5px blurred, lightblue box-shadow

Set the Spread Radius of the Shadow

The spread attribute sets the spread radius. A positive value makes the shadow larger, while a negative value makes it smaller.

A <div> element with a hazy, light blue box-shadow, extending 12 pixels.

Set the inset Parameter

The inset parameter modifies the shadow from an outer shadow (outset) to an inner shadow.

A <div> box with a shadow that is blurred, light blue, and appears inset.

Add Multiple Shadows

An object can also have various shadows:


Cards

You can use the box-shadow property to make cards that look like paper.