CSS3 Text Effects
CSS3 Text Effects
CSS3 includes several new text features.
In this chapter you will learn about the following text properties:
- text-shadow
- box-shadow
- text-overflow
- word-wrap
- word-break
Browser support
| property | |||||
|---|---|---|---|---|---|
| text-shadow | 4.0 | 10.0 | 3.5 | 4.0 | 9.5 |
| box-shadow | 10.0 | ||||
| 4.0 -webkit- | 9.0 | 4.0 | |||
| 3.5 -moz- | 5.1 | ||||
| 3.1 -webkit- | 10.5 | ||||
| text-overflow | 4.0 | 6.0 | 7.0 | 3.1 | 11.0 |
| 9.0 -o- | |||||
| word-wrap | 23.0 | 5.5 | 3.5 | 6.1 | 12.1 |
| word-break | 4.0 | 5.5 | 15.0 | 3.1 | 15.0 |
CSS3 Text Shadow
In CSS3, the text-shadow property applies shadows to text.

You specify the horizontal shadow, vertical shadow, blur distance, and shadow color:
Example
Add a shadow to a heading:
h1
{
text-shadow:
5
px
5
px
5
px
#FF0000
;
}
Try it »
CSS3 box-shadow Property
In CSS3, the box-shadow property applies shadows to boxes
Example
div
{
box-shadow:
10
px
10
px
5
px
#888888
;
}
Try it »
Next, add color to the shadow
Example
div
{
box-shadow:
10
px
10
px
grey
;
}
Try it »
Next, add a blur effect to the shadow
Example
div
{
box-shadow:
10
px
10
px
5
px
grey
;
}
Try it »
You can also add shadow effects to the ::before and ::after pseudo-elements
Example
boxshadow
{
position:
relative
;
box-shadow:
1
px
2
px
4
px
rgba
(
0
,
0
,
0
,
.5
)
;
padding:
10
px
;
background:
white
;
}
#boxshadow
img
{
width:
100
%
;
border:
1
px
solid
#8a4419
;
border-style:
inset
;
}
#boxshadow
:
:after
{
content:
''
;
position:
absolute
;
z-index:
1
;
/*
hide shadow behind image
*/
box-shadow:
0
15
px
20
px
rgba
(
0
,
0
,
0
,
0.3
)
;
width:
70
%
;
left:
15
%
;
/*
one half of the remaining 30%
*/
height:
100
px
;
bottom:
0
;
}
Try it »
A special use of shadows is the card effect
Example
div
.card
{
width:
250
px
;
box-shadow:
0
4
px
8
px
0
rgba
(
0
,
0
,
0
,
0.2
),
0
6
px
20
px
0
rgba
(
0
,
0
,
0
,
0.19
)
;
text-align:
center
;
}
Text Cards »
Image Cards »
CSS3 Text Overflow Property
The CSS3 text-overflow property specifies how overflowing content should be displayed to the user
Example
p
.test1
{
white-space:
nowrap
;
width:
200
px
;
border:
1
px
solid
#000000
;
overflow:
hidden
;
text-overflow:
clip
;
}
p
.test2
{
white-space:
nowrap
;
width:
200
px
;
border:
1
px
solid
#000000
;
overflow:
hidden
;
text-overflow:
ellipsis
;
}
Try it »
CSS3 Word Wrapping
If a word is too long to fit in an area, it extends outside:
In CSS3, the word-wrap property allows you to force text to wrap - even if it means breaking a word in the middle:
The CSS code is as follows:
Example
Allow long text to wrap:
p
{
word-wrap:
break-word
;
}
Try it »
CSS3 Word Breaking
The CSS3 word-break property specifies the line-breaking rules:
The CSS code is as follows:
Example
p
.test1
{
word-break:
keep-all
;
}
p
.test2
{
word-break:
break-all
;
}
Try it »
New Text Properties
| property | Description | CSS |
|---|---|---|
| hanging-punctuation | Specifies whether punctuation characters are placed outside the line box. | 3 |
| punctuation-trim | Specifies whether punctuation characters are trimmed. | 3 |
| text-align-last | Sets how the last line or the line immediately before a forced line break is aligned. | 3 |
| text-emphasis | Applies emphasis marks and the foreground color of the emphasis marks to an element's text. | 3 |
| text-justify | Specifies the alignment method used when text-align is set to "justify". | 3 |
| text-outline | Specifies the outline of the text. | 3 |
| text-overflow | Specifies what happens when text overflows its containing element. | 3 |
| text-shadow | Adds a shadow to text. | 3 |
| text-wrap | Specifies the line-breaking rules for text. | 3 |
| word-break | Specifies the line-breaking rules for non-CJK text. | 3 |
| word-wrap | Allows long unbreakable words to be broken and wrapped to the next line. | 3 |