View video tutorial

CSS Text Alignment

CSS

This property sets the horizontal alignment of a text.

CSS Text Alignment and Text Direction.

The following properties are about CSS text alignment and text direction.

  • text-align
  • text-align-last
  • direction
  • unicode-bidi
  • vertical-align

CSS Text Alignment.

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

Text alignment can be done in four ways.

  • left
  • right
  • center
  • justify

When the text-align property is set to "Justify", each line is stretched so that each line has the same width.

Example

#p1 {
  text-align: center;
}
#p2 {
  text-align: left;
}
#p3 {
  text-align: right;
}
#p4 {
  text-align: justify;
}
Try it Now »

Click on the "Try it Now" button to see how it works.


CSS Text Align Last.

The text-align-last property specifies how to align the last line of text.

Example

#p1 {
  text-align-last: right;
}
#p2 {
  text-align-last: center;
}
#p3 {
  text-align-last: justify;
}
Try it Now »

Click on the "Try it Now" button to see how it works.


CSS Text Direction

The direction and unicode-bidi attributes can be used to change the direction of an element's text.

Example

#p1 {
  direction: rtl;
  unicode-bidi: bidi-override;
}
Try it Now »

Click on the "Try it Now" button to see how it works.


CSS Vertical Alignment

The vertical-align property specifies the vertical alignment of an element.

Example

    #p1 {
      vertical-align: baseline;
    }

    #p2 {
      vertical-align: text-top;
    }

    #p3 {
      vertical-align: text-bottom;
    }

    #p4 {
      vertical-align: sub;
    }

    #p5 {
      vertical-align: super;
    }
Try it Now »

Click on the "Try it Now" button to see how it works.