CSS propertyTypography

text-align

Aligns text horizontally: left, right, center, or justified.

Initial value
start
Inherited
Yes
Animatable
no
Applies to
block containers
JavaScript
element.style.textAlign = "center"
On this page

Example

#
CSS
.cta {
  text-align: center;
}
Preview

Definition and usage

#

The text-align property sets the horizontal alignment of inline content inside a block: text, links, inline images, and inline-block elements. It doesn’t move the block itself, only what’s inside it, line by line.

The start and end values depend on the writing direction: in English, start means the left side, and in Arabic the right side. That way the layout adapts to the language on its own. justify stretches the lines so they touch both edges.

To center a block itself (not the text inside it), use auto margins, or Flexbox and Grid.

Syntax

#
Syntax
text-align: start | end | left | right | center | justify;

Values

#
  • start

    To the start of the line, the left in English.
  • center

    Every line centered.
  • end

    To the end of the line, the right in English.
  • justify

    Lines stretched to both edges, except the last one.

Values in practice

#

start

To the start of the line, the left in English.
.demo { text-align: start; }

center

Every line centered.
.demo { text-align: center; }

end

To the end of the line, the right in English.
.demo { text-align: end; }

justify

Lines stretched to both edges, except the last one.
.demo { text-align: justify; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Align long paragraphs to the left. Centered and justified text is harder to read, and justifying creates gaps between words.
  • Use start and end instead of left and right if the site has versions in right-to-left languages.

Related entries

#

Spotted a mistake or missing an example? Write to us.