This site is 📱 accessible. Tap here to use the mobile stylesheet.

4.1.1 Text Alignment

The text-align property is used to set the horizontal alignment of a text. 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 1
h1 {
  text-align: center;
}

h2 {
  text-align: left;
}

h3 {
  text-align: right;
}

Text Direction

The direction and unicode-bidi properties can be used to change the text direction of an element:

Example 2
p {
  direction: rtl;
  unicode-bidi: bidi-override;
}

Vertical Alignment

The vertical-align property sets the vertical alignment of an element. This example demonstrates how to set the vertical alignment of an image in a text:

Example 3
img.top {
  vertical-align: top;
}

img.middle {
  vertical-align: middle;
}

img.bottom {
  vertical-align: bottom;
}