What is alignment web design

text-align

The CSS property determines the horizontal alignment of a block element or a table cell frame. This means that it works as it is, but in a horizontal direction.

The source for this interactive example is stored in a GitHub repository. If you would like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

syntax

The property is specified in one of the following ways:

values

The same as if is and if is.
The same as if is and if is.
The inline content is aligned to the left (left-justified) of the line box.
The inline content is aligned on the right edge (right-justified) of the line box.
The inline content is centered within the line box.
The text is justified. Text should align its left and right margins flush with the left and right margins of the paragraph content.
Same as, but forces the last line to be justified as well.
Similar to, with the difference that the values ​​and in relation to those of the parent element are calculated and replaced by the appropriate or value.
When applied to a table cell, specifies the character around which the contents of the cell are aligned.

Accessibility concerns

The inconsistent spacing between words created by justified text can be problematic for people with cognitive problems like dyslexia.

Formal definition

Initial value or a nameless value that behaves as if has the value, if has the value, if not supported by the browser.
Applicable toBlock container
InheritedYes
Calculated valueas specified, except for the value which is calculated in relation to the value of the parent element and results in a calculated value of or
Animation typediscreet

Formal syntax

start | end | left | right | center | justify | match-parent

Examples

Left justified

HTML

CSS

Result

Centered

HTML

CSS

Result

Justified

HTML

CSS

Result

Note

The standard-compatible way to center a block yourself without centering its inline content is e.g. to set the left and right to, e.g .:

Specifications

Browser compatibility

BCD tables only load in the browser

See also