Text Shadows in CSS

Text shadows are created with the text-shadow CSS property. It takes a list of shadows separated by commas to be applied to the text and any of its styles. Each shadow is defined by a combination of the element's X and Y offsets, blur radius and color.

Each shadow is defined by two or three <length> values, followed by a <color> value if desired. The <offset-x> and <offset-y> values are the first two <length> values. The blur-<radius> value is the third, optional, length value. The <color> of the shadow is represented by the <color> value.

Shadows are applied front-to-back when more than one is provided, with the very first shadow on top.

Syntax

The following is the syntax for making a basic text-shadow. The first two variables determine the position of your shadow, the third determines the level of blur, and the fourth determines the color of the shadow.

text-shadow: <offset-x> <offset-y> blur-radius color | none |initial | inherit;
  • Insert a comma-separated list of shadows to the text if you want to add more than one shadow.

Example:

text-shadow: 0 0 55px black, 0 1px 0 rgba(0,0,0, .25);

Property Values

  <offset-x> <offset-y>  Required  The shadow's distance from the text is specified by these <length> variables. The horizontal distance is specified by offset-x; a negative value places the shadow to the left of the text. The vertical distance is specified by offset-y; a negative value throws the shadow over the text. If both values are 0, the shadow is put precisely below the text, however owing to the impact of <blur-radius>, it may be partially visible.  
  blur-radius  Optional  This is a value of the type <length>. The blur gets greater as the value goes up; the shadow gets wider and lighter. It defaults to 0 if not supplied.  
  color  Optional  The shade of the shadow's color. It can either come before or after the offset values. If left unknown, the color's value is determined by the user agent; therefore, if cross-browser consistency is needed, you should specify it explicitly.  
  none  Default  No Shadow  
  initial     Sets this property to its default value.  
  inherit   Inherits this property from its parent element.  

Also, keep in mind that you may utilize RGBA values for color, such as a white transparency of 40%:

p{      
       text-shadow: 0px 2px 2px rgba(255, 255, 255, 0.4);
}

It is not a compulsion to use rgba for shadow color; we may use any of the CSS colorways instead. However, for a shadow, rgba is the best color option since it offers an additional dimension to interact with. The alpha value may be used to control the opacity of the shadow as well as its location, blur, and color.

This is really easier than dealing with other color approaches since you don't have to go looking for a good accent color that is slightly darker or lighter than the backdrop color. You may use black or white in RGBA and lower the opacity to mix it in with the backdrop.

Single Shadow

Example:

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

Multiple shadows

Here’s the basic outline of the syntax. There’s a comma after the first two shadows and a semicolon after the last shadow.

text-shadow: shadow1, shadow2, shadow3;

Example:

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

Type of Shadows

The beautiful thing about text-shadows is that they can be used for a lot more than drop shadows.

Letterpress

The first step is to make the text color a shade darker than the background color. Apply a soft white text-shadow with a low opacity next.

Set the background color to #222 and the text to black with 60% opacity. Finally, a white shadow with 10% opacity was positioned slightly below and to the right.

body {
    background: #222;
}
#text h1 {
    color: rgba(0,0,0,0.6);
    text-shadow: 2px 2px 3px rgba(255,255,255,0.1);

Output:

Text Shadows In CSS

Hard Shadow

Your shadow does not need to be blurred in any way. Hard text shadows are popular due to their vintage appeal.

text-shadow: 6px 6px 0px rgba(0,0,0,0.2);

Output:

Text Shadows In CSS

Double Shadow

The concept is to use two shadows, the first of which should be the same hue as your background.

text-shadow: 4px 3px 0px #fff, 9px 8px 0px rgba(0,0,0,0.15);

Output:

Text Shadows In CSS

Down and Distant

The results are easily impressive once you start stacking up on the shadows. It's quite simple to begin creating some fantastic faux 3D effects that your web design smart consumers won't think is live text.

I used four shadows in total, all pointing straight down and with different degrees of length and blur.

text-shadow: 0px 3px 0px #b2a98f,
                 0px 14px 10px rgba(0,0,0,0.15),
                 0px 24px 2px rgba(0,0,0,0.1),
                 0px 34px 30px rgba(0,0,0,0.1);

Output:

Text Shadows In CSS

Close and Heavy

Another variation on the same theme, this time with three shadows placed considerably closer to the source. The effect gives your words a bit more weight.

text-shadow: 0px 4px 3px rgba(0,0,0,0.4),
             0px 8px 13px rgba(0,0,0,0.1),
             0px 18px 23px rgba(0,0,0,0.1);

Output:

Text Shadows In CSS

Mark Dotto’s Seriously 3D Text

Here's one that I've always felt was very outstanding. It makes use of a whopping twelve different shadows to create a very convincing 3D illusion.

text-shadow: 0 1px 0 #ccc, 
               0 2px 0 #c9c9c9,
               0 3px 0 #bbb,
               0 4px 0 #b9b9b9,
               0 5px 0 #aaa,
               0 6px 1px rgba(0,0,0,.1),
               0 0 5px rgba(0,0,0,.1),
               0 1px 3px rgba(0,0,0,.3),
               0 3px 5px rgba(0,0,0,.2),
               0 5px 10px rgba(0,0,0,.25),
               0 10px 10px rgba(0,0,0,.2),
               0 20px 20px rgba(0,0,0,.15);

Output:

Text Shadows In CSS

Gordon Hall’s True Inset Text

Gordon used some serious CSS wizardry to achieve not only an exterior but also a true inside shadow. A comprehensive explanation of the approach may be found in his blog article.

background-color: #666666;
    -webkit-background-clip: text;
    -moz-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: rgba(255,255,255,0.5) 0px 3px 3px;

Output:

Text Shadows In CSS

Soft Emboss

color: rgba(0,0,0,0.6);
text-shadow: 2px 8px 6px rgba(0,0,0,0.2), 0px -5px 35px rgba(255,255,255,0.3);

Output:

Text Shadows In CSS

Text-shadows, like other CSS effects, are relatively simple to construct in their most basic form, but they may take on a number of various shapes if you put some effort into them. You may layer CSS shadows on top of each other using commas as a divider to drastically increase the effect's intrigue and realism.


Related Topics

Bootstrap Buttons Groups

Bootstrap 4 Button Group Bootstrap 4 provides a feature button group that helps in creating a series of buttons together in a group. Basic Button Group  The .btn-group class is used within the <div> tag to create a...

6 minutes read.

Bootstrap Glyphicons

Bootstrap Glyphicon is used to create different type of glyphicons It is used in the web project. It provides 260 Glyphicons from the Glyphivons Halflings set. There are various examples of...

1 minute read.

Bootstrap Pager

← Prev Next → ...

1 minute read.

Bootstrap Notification Bubble

What is a notification bubble? Bubbles are built into the Notification system. They float on top of the website or the button to indicate pending notifications. Bubbles can be expanded to reveal...

5 minutes read.

Bootstrap 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 minutes read.

Bootstrap 4 Modal

Bootstrap 4 Modal The Modal is a component of Bootstrap 4, which is a dialog box or pop-up window. The modals are used to provide information or warning to the user, such as...

18 minutes read.

Bootstrap 4 Icons

Bootstrap 4 Icons Bootstrap 3 contains the default icon library. But in bootstrap 4, you have to include the external icon library by yourself. Many free icon libraries are available such...

2 minutes read.

Bootstrap Panels

A bootstrap panel is used to create bordered box with some padding around its content. It is created with the .panels classes, and .panel-body classes. There are following classes of the panel: Panel header Panel...

4 minutes read.

Bootstrap 4 Layout

Containers Containers are the essential elements of the bootstrap layout. It is required when we are using a bootstrap grid system. Containers can also be nested, but most layouts do not need nested containers. Bootstrap has...

3 minutes read.

Bootstrap Tables

We can create different types of responsive and awesome bootstrap table like: striped , border etc. Bootstrap Basic Table We can create a basic bootstrap table by using its class .table. It has...

3 minutes read.

Bootstrap Searchable Dropdown Menu

Searchable Dropdown Menu When we click on the dropdown button/arrow in this dropdown menu, an input field will pop up with all the dropdown items listing inside. If we type in...

5 minutes read.

Bootstrap Badges and Labels

Bootstrap Badges Bootstrap Badges are numerical indicators. It is used to show that how many items are associated with a link.The .badge class is used to create of Bootstrap Badges. Let us see...

2 minutes read.

Bootstrap Contact Us page

What is a “Contact Us” page? A “Contact Us” page is a web page available on the websites of various companies, organisations etc., for its users to contact the organisation or...

5 minutes read.

Bootstrap 4 Spinners

Bootstrap 4 offers spinner is a loading indicator that is used to display the loading state of any component or web page. The spinner is also known as a loader...

7 minutes read.

Bootstrap 4 Margin classes

Bootstrap 4 contains a variety of brief, responsive margin and padding utility classes to change the appearance of an element. The Bootstrap 4 margin classes use for the outer spacing of...

8 minutes read.

Bootstrap 4 Jumbotron

Bootstrap 4 Jumbotron Bootstrap offers Jumbotron, which is used to get more attention to specific content or information on the web page. It provides a gray background-color to the content to make that content...

2 minutes read.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

Bootstrap Input groups

Bootstrap 4 Input groups The input group is a component of Bootstrap 4, which is used to create interactive and stylish form controls. With the help of input groups, you can easily customize the input...

8 minutes read.

Bootstrap List group

Bootstrap list group provides a group of a list of items. The most basic list is an unordered list. We can use <ul> element with .list-group class and <li> element with .lsit-group-item. Let us see...

3 minutes read.

Bootstrap 4 List Groups

Bootstrap 4 List Groups Bootstrap 4 offers List Group component, which is used to display a series of content in an organized way. The most common list group is an unordered...

13 minutes read.