Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS Text

CSS Text Formatting

Text Formatting

This text is styled with some of the text formatting properties. The heading uses the text-align, text-transform, and color properties. The paragraph is indented, aligned, and the space between characters is specified. The underline is removed from the "Try it" link.


Text Colors

The color property is used to set the color of the text.

Colors are most often specified in CSS as:

See A CSS color value View the complete color values.

The background color of a web page is specified in the body selector:

Example

body

{

color:

red

;

}

h1

{

color:

#00ff00

;

}

h2

{

color:

rgb

(

255

,

0

,

0

)

;

}

Try it »

Remark For W3C-standard CSS: if you define a color property, you must also define a background-color property.


Text Alignment

The text-align property is used to set the horizontal alignment of text.

Text can be centered, aligned to the left or right, or justified.

When text-align is set to "justify", each line is expanded to equal width, with the left and right margins aligned (as in magazines and newspapers).

Example

h1

{

text-align:

center

;

}

p

.date

{

text-align:

right

;

}

p

.main

{

text-align:

justify

;

}

Try it »


Text decoration

The text-decoration property is used to set or remove text decorations.

From a design perspective, the text-decoration property is mainly used to remove the underline from links:

Example

a

{

text-decoration:

none

;

}

Try it »

Text can also be decorated in this way:

Example

h1

{

text-decoration:

overline

;

}

h2

{

text-decoration:

line-through

;

}

h3

{

text-decoration:

underline

;

}

Try it »

Remark We do not recommend emphasizing text that is not a link, because this often confuses users.


Text Transformation

The text-transform property is used to specify uppercase and lowercase letters in a text.

It can be used to make all sentences uppercase or lowercase, or to capitalize the first letter of each word.

Example

p

.uppercase

{

text-transform:

uppercase

;

}

p

.lowercase

{

text-transform:

lowercase

;

}

p

.capitalize

{

text-transform:

capitalize

;

}

Try it »


Text Indentation

The text-indent property is used to specify the indentation of the first line of a text.

Example

p

{

text-indent:

50

px

;

}

Try it »


More examples

Specifying the Space Between Characters
This example demonstrates how to increase or decrease the space between characters.

Specifying the Space Between Lines
This example demonstrates how to specify the space between lines in a paragraph.

Set the text direction of an element
This example demonstrates how to change the text direction of an element.

Increasing the White Space Between Words
This example demonstrates how to increase the white space between words in a paragraph.

Disabling Text Wrapping Within an Element
This example demonstrates how to disable text wrapping within an element.

Vertically Aligning an Image
This example demonstrates how to vertically align an image with text.

Adding Text Shadow
This example demonstrates how to set a text shadow.


All CSS text properties.

property Description
color Set the text color.
direction Set the text direction.
letter-spacing Sets the spacing between characters.
line-height Sets the line height.
text-align Align the text in an element.
text-decoration Add decorations to text.
text-indent Indent the first line of text in an element.
text-shadow Set the text shadow.
text-transform Control the letters in an element.
unicode-bidi Set or return whether text is overwritten. 
vertical-align Set the vertical alignment of an element.
white-space Set how white space in an element is handled.
word-spacing Set the letter spacing.