CSS Text

Text Color

With CSS, a color is most often specified by:

  • a HEX value – like “#ff0000”
  • an RGB value – like “rgb(255,0,0)”
  • a color name – like “red”

The default color for your website is defined in the body selector:

body {
 color: blue;
}

h1 {
 color: #00ff00;
}

h2 {
 color: rgb(255,0,0);
}

 

Text Alignment

The text alignment property is used to set the horizontal alignment of a text. The text can be centered, right or left aligned, or justified. When text-align is set to “justify,” each line is stretched so that every line has equal width, and the right and left margins are straight like you see in newspapers and magazines.

h1 {
text-align: center;
}

p.date {
text-align: right;
}

p.main {
text-align: justify;
}

 

Text Decoration

The text-decoration property is used to set or remove decorations from text; the underlines from links.

a {
text-decoration: none;
}

 

The property can also be used to decorate text:

 

h1 {
text-decoration: overline;
}

h2 {
text-decoration: line-through;
}

h3 {
text-decoration: underline;
}

 

Text Transformation

The text-transform property is used to specify text to be uppercase or lowercase letters, or capitalize the first letter of each word:

p.uppercase {
text-transform: uppercase;
}

p.lowercase {
text-transform: lowercase;
}

p.capitalize {
text-transform: capitalize;
}

 

Text Indentation

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

p {
 text-indent: 50px;
}

 

Other CSS Text Properties

letter-spacing Increases or decreases the space between characters in a text
line-height Sets the line height
text-shadow Specifies the shadow effect added to text
word-spacing Increases or decreases the space between words in a text
vertical-align Sets the vertical alignment of an element