WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Text


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 this colored "Try it yourself" link.


Text Color

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

With CSS, a color is most often specified by:

  • a color name - like "red"
  • a HEX value - like "#ff0000"
  • an RGB value - like "rgb(255,0,0)"

Look at CSS Color Values for a complete list of possible color values.

The default text color for a page is defined in the body selector.

Example

body {
    color: blue;
}

h1 {
    color: green;
}
Try it yourself »
F property.

Text Alignment

The text-align property specifies the horizontal alignment of text in an element.

A text can be left or right aligned, centered, or justified.

The following example shows center aligned, and left and right aligned text (left alignment is default if text direction is left-to-right, and right alignment is default if text direction is right-to-left):

Example

h1 {
    text-align: center;
}

h2 {
    text-align: left;
}

h3 {
    text-align: right;
}
Try it yourself »

Text Decoration

The text-decoration property specifies how the text will be decorated.

The value text-decoration: none; is often used to remove underlines from links:

Example

a {
    text-decoration: none;
}
Try it yourself »

The other text-decoration values are used to decorate text:

Example

h1 {
    text-decoration: overline;
}

h2 {
    text-decoration: line-through;
}

h3 {
    text-decoration: underline;
}
Try it yourself »

inherit - Inherits this property from its parent element overline - Draws a horizontal line above the text underline - Draws a horizontal line below the text line-through - draws a horizontal line through the text (substitutes the HTML <s> tag)


Text Transformation

The text-transform property specifies how to capitalize an element's text.

It can be used to turn everything into capitalize the first letter of each word:

Example


p.capitalize {
    text-transform: capitalize;
}
Try it yourself »

Text Indentation

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

Example

p {
    text-indent: 50px;
}
Try it yourself »

Letter Spacing

The letter-spacing property specifies the space between characters in a text.

The values can be set as the space between characters:

Example

h1 {
    letter-spacing: 4px;
}

h2 {
    letter-spacing: -4px;
}

p {
    letter-spacing: 4px;
}
Try it yourself »

Line Height

The line-height property is used to specify the space between lines:

Example

p.small {
    line-height: 0.6;
}

p.big {
    line-height: 1.6;
}
Try it yourself »

Text Direction

The direction property is used to change the text direction of an element:

Example

div {
    direction: rtl;
}
Try it yourself »

Word Spacing

The word-spacing property is used to specify the space between the words in a text.

The following example demonstrates how to increase or decrease the space between words: 

Example

h1 {
    word-spacing: 10px;
}

h2 {
    word-spacing: -5px;
}
Try it yourself »