This type of alignment positions the text so that it is aligned with the right margin

The text-align CSS property sets the horizontal alignment of the inline-level content inside a block element or table-cell box. This means it works like vertical-align but in the horizontal direction.

Try it

Syntax

/* Keyword values */ text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: match-parent; /* Character-based alignment in a table column */ text-align: "."; text-align: "." center; /* Block alignment values (Non-standard syntax) */ text-align: -moz-center; text-align: -webkit-center; /* Global values */ text-align: inherit; text-align: initial; text-align: revert; text-align: revert-layer; text-align: unset;

The text-align property is specified in one of the following ways:

  • Using the keyword values start, end, left, right, center, justify, justify-all, or match-parent.
  • Using a <string> value only, in which case the other value defaults to right.
  • Using both a keyword value and a <string> value.

Values

start

The same as left if direction is left-to-right and right if direction is right-to-left.

end

The same as right if direction is left-to-right and left if direction is right-to-left.

left

The inline contents are aligned to the left edge of the line box.

right

The inline contents are aligned to the right edge of the line box.

center

The inline contents are centered within the line box.

justify

The inline contents are justified. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line.

justify-all Experimental

Same as justify, but also forces the last line to be justified.

match-parent

Similar to inherit, but the values start and end are calculated according to the parent's direction and are replaced by the appropriate left or right value.

<string> Experimental

When applied to a table cell, specifies the alignment character around which the cell's contents will align.

Accessibility concerns

The inconsistent spacing between words created by justified text can be problematic for people with cognitive concerns such as Dyslexia.

  • MDN Understanding WCAG, Guideline 1.4 explanations
  • Understanding Success Criterion 1.4.8 | Understanding WCAG 2.0

Formal definition

Formal syntax

text-align =
start |
end |
left |
right |
center |
justify |
match-parent |
justify-all

Examples

Start alignment

HTML

<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>

CSS

.example { text-align: start; border: solid; }

Result

Centered text

HTML

<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>

CSS

.example { text-align: center; border: solid; }

Result

Example using "justify"

HTML

<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>

CSS

.example { text-align: justify; border: solid; }

Result

Specifications

Specification
CSS Logical Properties and Values Level 1
# text-align
CSS Text Module Level 3
# text-align-property

Browser compatibility

BCD tables only load in the browser

See also

What is the type of alignment positions for the text so that it is aligned with the right margin?

Horizontal alignment determines how the left and right edges of a paragraph fit between the margins, while vertical alignment determines the placement of the text between the upper and lower margins.

How do you align text on the right margin?

Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .

What is the alignment of text that is positioned so that both the left and right edges of the paragraph are flush with the left and right margins?

justify is to format a paragraph so the text is distributed evenly across the page between the left and right margins, and both the left and right edges of the paragraph are aligned at the margins.

What is the alignment of text called?

The type alignment setting is sometimes referred to as text alignment, text justification, or type justification.

Toplist

Neuester Beitrag

Stichworte