CSS text-align-last Property

The CSS text-align-last property controls the alignment of the last line of text in a block container and lines immediately before a forced line break.

It is especially useful with justified paragraphs, where the final line normally follows the text direction rather than stretching across the available width. The property can align that line to the start, end, left, right, or center, or justify it independently of the other lines.

text-align-last Syntax

The text-align-last property accepts alignment keywords that determine how the final line of a block or a line immediately before a forced break is positioned.

Basic Syntax

p {
  text-align-last: center;
}

Common Values

p {
  text-align-last: auto;
}
p {
  text-align-last: start;
}
p {
  text-align-last: end;
}
p {
  text-align-last: left;
}
p {
  text-align-last: right;
}
p {
  text-align-last: center;
}
p {
  text-align-last: justify;
}

CSS-Wide Keywords

p {
  text-align-last: initial;
}
p {
  text-align-last: inherit;
}
p {
  text-align-last: unset;
}
p {
  text-align-last: revert;
}
p {
  text-align-last: revert-layer;
}

The initial value is auto, which determines last-line alignment from the applicable text alignment behavior.

Property Values

Value Description
auto Uses the applicable text-align behavior, except that justified text uses start alignment for its final line.
start Aligns the affected line to the logical start edge according to the text direction.
end Aligns the affected line to the logical end edge according to the text direction.
left Aligns the affected line to the physical left side in horizontal writing.
right Aligns the affected line to the physical right side in horizontal writing.
center Centers the affected line within the available line width.
justify Justifies the affected line by distributing spacing across the available width.
initial Resets the property to auto.
inherit Uses the computed value from the parent element.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited Yes
Applies to Block containers
Computed value As specified
Animation type Discrete
Percentages Not accepted
Related properties text-align, text-justify, direction, writing-mode
Specification CSS Text Module Level 3

Valid Examples

p {
  text-align-last: center;
}
p {
  text-align-last: justify;
}
blockquote {
  text-align-last: end;
}
.description {
  text-align-last: start;
}
.footer-text {
  text-align-last: right;
}

Invalid Examples

p {
  text-align-last: middle;
}
p {
  text-align-last: top;
}
p {
  text-align-last: 50%;
}
p {
  text-align-last: 20px;
}
p {
  text-align-last: center justify;
}

Unsupported keywords, lengths, percentages, and multiple alignment values are invalid.

How It Works

The text-align-last property affects the final line of a block container and lines immediately before forced line breaks. Other lines continue to follow the applicable text-align value.

Step 1: Create a Paragraph

<p class="example-text">
  CSS provides properties for controlling text alignment.
  The last line can use a different alignment from the
  preceding lines.
</p>

Step 2: Justify the Paragraph

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

The browser justifies eligible lines while the final line normally aligns to the start edge.

Step 3: Center the Last Line

.example-text {
  text-align: justify;
  text-align-last: center;
}

The preceding lines remain justified, while the final line is centered.

Step 4: Justify the Last Line

.example-text {
  text-align: justify;
  text-align-last: justify;
}

The final line is also justified. If the line contains very little text, the spacing may appear unusually large.

Important Consideration

The property can also affect a paragraph containing only one line because that line is both its first and last line.

Automatic Last-Line Alignment

The auto value is the default. It follows the applicable text alignment behavior, with special handling for justified text.

Automatic Alignment With Left-Aligned Text

.example-text {
  text-align: left;
  text-align-last: auto;
}

The final line follows the left alignment.

Automatic Alignment With Centered Text

.example-text {
  text-align: center;
  text-align-last: auto;
}

The final line remains centered.

Automatic Alignment With Justified Text

.example-text {
  text-align: justify;
  text-align-last: auto;
}

The final line aligns to the logical start edge instead of being stretched across the available width.

Why auto Is Useful

The default behavior is suitable for most paragraphs because it preserves natural last-line alignment without requiring an additional declaration.

Physical Alignment

Physical alignment values position the affected line relative to a specific side of the line box.

Left Alignment

.last-left {
  text-align-last: left;
}

Aligns the final line to the left side in horizontal writing.

Right Alignment

.last-right {
  text-align-last: right;
}

Aligns the final line to the right side in horizontal writing.

Center Alignment

.last-center {
  text-align-last: center;
}

Centers the final line within the available line width.

Comparing Physical Values

Value Result in Horizontal Writing
left Final line aligns to the left.
right Final line aligns to the right.
center Final line is centered.

Important Consideration

Physical alignment is appropriate when the affected line must remain on a particular side. Logical alignment is generally more adaptable for multilingual content.

Logical Alignment

The start and end values respond to the text direction and writing mode.

Start Alignment

.last-start {
  text-align-last: start;
}

In horizontal left-to-right text, the final line aligns to the left. In horizontal right-to-left text, it aligns to the right.

End Alignment

.last-end {
  text-align-last: end;
}

In horizontal left-to-right text, the final line aligns to the right. In horizontal right-to-left text, it aligns to the left.

Logical Alignment Comparison

Value LTR RTL
start Left Right
end Right Left
left Left Left
right Right Right

Using the HTML dir Attribute

<p dir="rtl" class="last-start">
  نص باللغة العربية
</p>

The dir attribute establishes the text direction, allowing logical alignment to follow it.

When to Use Logical Alignment

Use start and end when the same styles must work with left-to-right and right-to-left languages.

Justified Text

The text-align-last property is particularly useful when a paragraph uses text-align: justify.

Default Justified Paragraph

.justified-paragraph {
  text-align: justify;
  text-align-last: auto;
}

Eligible lines are justified, while the final line aligns to the logical start edge.

Centered Final Line

.justified-paragraph {
  text-align: justify;
  text-align-last: center;
}

The final line is centered without changing the justification of the preceding lines.

Right-Aligned Final Line

.justified-paragraph {
  text-align: justify;
  text-align-last: right;
}

The final line aligns to the right in horizontal writing.

Justified Final Line

.justified-paragraph {
  text-align: justify;
  text-align-last: justify;
}

The final line is stretched across the available width by adjusting spacing according to the browser's justification behavior.

Justification and Word Spacing

Justifying a short final line can create large gaps between words. The result depends on the text, line width, language, and browser's justification algorithm.

Using text-justify

.justified-paragraph {
  text-align: justify;
  text-align-last: justify;
  text-justify: inter-word;
}

The text-justify property can influence how spacing is distributed during justification. Browser support varies.

Important Consideration

For most body text, the default last-line alignment is easier to read than forcing a short final line to fill the entire width.

Forced Line Breaks

The property also affects lines immediately before forced line breaks, such as those created with the HTML <br> element.

HTML Example

<p class="break-example">
  First line of text<br>
  Second line of text<br>
  Final line of text
</p>

CSS Example

.break-example {
  text-align: left;
  text-align-last: center;
}

Each line ending at a forced break, as well as the final line, uses the specified last-line alignment.

Using Right Alignment

.break-example {
  text-align: left;
  text-align-last: right;
}

The affected lines align to the right in horizontal writing.

Automatic Line Wrapping

Lines created automatically because text reaches the container width are not treated as final lines unless they are the last line of the block.

Important Consideration

A forced line break differs from an automatically wrapped line. The property targets the final line and lines immediately preceding forced breaks, not every wrapped line.

Relationship to text-align

The text-align and text-align-last properties work together, but they control different aspects of line alignment.

Property Purpose
text-align Controls the general alignment of inline content within a block container.
text-align-last Controls the alignment of the final line and lines immediately before forced breaks.
text-justify Controls aspects of spacing distribution during text justification.
direction Establishes the base text direction used by logical alignment values.

Centering All Lines

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

All lines are centered, including the final line under the default text-align-last: auto behavior.

Justifying Most Lines

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

Eligible lines are justified, while the final line normally aligns to the logical start edge.

Justifying With a Centered Final Line

.example-text {
  text-align: justify;
  text-align-last: center;
}

Eligible lines remain justified, but the final line is centered.

Using Different Alignments

.example-text {
  text-align: left;
  text-align-last: right;
}

Ordinary lines align left, while the final line and lines before forced breaks align right.

Important Consideration

The text-align-last property can override the alignment of affected lines even when text-align uses a different value.

Practical Examples

Centered Final Line

.article-paragraph {
  text-align: justify;
  text-align-last: center;
}

Justifies the paragraph while centering its final line.

Right-Aligned Final Line

.article-paragraph {
  text-align: justify;
  text-align-last: right;
}

Places the final line at the right edge in horizontal writing.

Direction-Aware Final Line

.multilingual-text {
  text-align: justify;
  text-align-last: start;
}

Aligns the final line to the logical beginning of the text direction.

End-Aligned Final Line

.description {
  text-align: start;
  text-align-last: end;
}

Uses start alignment for ordinary lines and end alignment for the final line.

Justifying Every Line

.fully-justified {
  text-align: justify;
  text-align-last: justify;
}

Justifies eligible lines and the final line.

Centered Text With a Start-Aligned Final Line

.centered-content {
  text-align: center;
  text-align-last: start;
}

Centers ordinary lines while aligning the final line to the logical start edge.

Single-Line Heading

.single-line-heading {
  text-align-last: center;
}

Centers the heading when its text occupies a single line.

Resetting Last-Line Alignment

.default-paragraph {
  text-align-last: initial;
}

Restores the initial value of auto.

Responsive Last-Line Alignment

.responsive-paragraph {
  text-align: justify;
  text-align-last: start;
}
@media (min-width: 768px) {
  .responsive-paragraph {
    text-align-last: center;
  }
}

Uses start alignment on smaller screens and centers the final line on larger screens.

text-align-last Example

This example compares four last-line alignment values. Each paragraph uses justified text so the effect on the final line is easy to see.

HTML Example

<div class="text-align-last-demo">
  <div class="alignment-example">
    <h4>text-align-last: auto</h4>
    <p class="last-auto">CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.</p>
  </div>
  <div class="alignment-example">
    <h4>text-align-last: center</h4>
    <p class="last-center">CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.</p>
  </div>
  <div class="alignment-example">
    <h4>text-align-last: right</h4>
    <p class="last-right">CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.</p>
  </div>
  <div class="alignment-example">
    <h4>text-align-last: justify</h4>
    <p class="last-justify">CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.</p>
  </div>
</div>

CSS Example

.text-align-last-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.text-align-last-demo .alignment-example {
  padding: 12px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}
.text-align-last-demo h4 {
  margin: 0 0 10px;
  font-size: 14px;
}
.text-align-last-demo p {
  margin: 0;
  padding: 12px;
  min-height: 140px;
  background: #fff;
  line-height: 1.6;
  text-align: justify;
}
.text-align-last-demo .last-auto {
  text-align-last: auto;
}
.text-align-last-demo .last-center {
  text-align-last: center;
}
.text-align-last-demo .last-right {
  text-align-last: right;
}
.text-align-last-demo .last-justify {
  text-align-last: justify;
}
Browser Result

text-align-last: auto

CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.

text-align-last: center

CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.

text-align-last: right

CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.

text-align-last: justify

CSS controls the alignment of text within a paragraph. The final line can follow the default behavior or use a different alignment.

All four paragraphs use text-align: justify. The difference is how their final lines are positioned. The automatic value aligns the last line to the start, the centered value centers it, the right value aligns it to the right, and the justify value distributes spacing across the final line.

Comparing the Results

Value Final Line Behavior
auto Aligns to the logical start edge when text-align is justify.
center Centers the final line.
right Aligns the final line to the right in horizontal writing.
justify Justifies the final line.

Changing to Logical Alignment

.text-align-last-demo .last-right {
  text-align-last: end;
}

The final line now aligns to the logical end of the text direction.

Changing the Text Direction

.text-align-last-demo .alignment-example {
  direction: rtl;
}

The logical start and end positions reverse in horizontal right-to-left writing, while physical left and right values remain tied to their respective sides.

Centering All Lines

.text-align-last-demo p {
  text-align: center;
  text-align-last: center;
}

Every line is centered, including the final line.

Accessibility Considerations

Last-line alignment can affect readability and the visual consistency of paragraphs, particularly when text is justified.

Avoid Excessive Word Spacing

Using text-align-last: justify on short final lines can create large gaps between words, making the text more difficult to read.

Prefer Natural Alignment for Body Text

For long paragraphs, the default last-line alignment generally provides a more natural reading experience.

Use Center Alignment Selectively

Centering the final line may be appropriate for decorative text or short quotations, but it can look inconsistent in ordinary body text.

Support Different Writing Directions

Logical values such as start and end are useful for content that may appear in left-to-right or right-to-left languages.

Test at Different Viewport Widths

The amount of text on the final line changes as the container width changes. Test the result on narrow and wide screens.

Avoid Forced Breaks for Visual Alignment

Do not insert unnecessary <br> elements solely to control text appearance. Allow text to wrap naturally whenever possible.

Preserve Document Meaning

The property changes visual alignment but does not alter text content, semantic structure, or reading order.

Common Mistakes

Using middle Instead of center

p {
  text-align-last: middle;
}

The correct value for centering the final line is center.

Expecting Every Line to Change

The property affects the final line and lines immediately before forced breaks, not every automatically wrapped line.

Confusing text-align-last With text-align

Use text-align for general line alignment and text-align-last for the affected final or forced-break lines.

Expecting auto to Always Mean start

The auto value follows the applicable text-align behavior. It uses start alignment specifically when the text is justified.

Justifying Very Short Final Lines

Short lines can develop large gaps between words when text-align-last: justify is applied.

Ignoring Forced Line Breaks

Lines immediately before forced breaks are also affected by the property.

Using Unsupported Values

p {
  text-align-last: spread;
}

The spread keyword is not valid.

Using Percentages or Lengths

p {
  text-align-last: 50%;
}

The property accepts alignment keywords rather than numeric lengths or percentages.

Assuming left and start Are Identical

In horizontal right-to-left text, start aligns to the right, while left remains left-aligned.

Ignoring Inheritance

The property is inherited, so descendant block containers may use the same last-line alignment unless another value is specified.

Expecting Smooth Animation

The property uses discrete animation and does not smoothly interpolate between alignment values.

Important Considerations

Keep the following points in mind when using text-align-last:

  • It controls the alignment of the final line in a block container.
  • It also affects lines immediately before forced line breaks.
  • The initial value is auto.
  • The property is inherited.
  • It accepts auto, start, end, left, right, center, and justify.
  • The auto value follows the applicable text alignment behavior.
  • For justified text, auto aligns the final line to the logical start edge.
  • The center value centers the affected line.
  • The justify value stretches the affected line using text justification.
  • Short justified final lines can produce excessive word spacing.
  • Logical values respond to the text direction.
  • Physical values refer to physical sides in horizontal writing.
  • The property works with text-align.
  • It can override the general alignment for affected lines.
  • It can affect a single-line block because its only line is also its final line.
  • Automatically wrapped lines are not all treated as final lines.
  • Forced line breaks can be created with <br>.
  • It does not change the text content or document order.
  • It does not control the position of the block container itself.
  • It does not accept lengths or percentages.
  • It is discretely animated.
  • The appearance depends on the amount of text in the final line.
  • Responsive widths can change where the final line begins.
  • Use logical alignment for multilingual content.
  • Test justified text for readability.
  • Use the default behavior when a special last-line alignment is unnecessary.

Browser Support

The CSS text-align-last property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.

Common values such as auto, left, right, center, and justify are supported in current browser versions. Older browsers may have limited support or require historical vendor-prefixed implementations.

For current compatibility information, visit Can I Use? and search for text-align-last.

Feature Detection

@supports (text-align-last: center) {
  .special-paragraph {
    text-align-last: center;
  }
}

Feature queries can test whether a browser recognizes the property and value.

Fallback Behavior

.special-paragraph {
  text-align: center;
  text-align-last: center;
}

If text-align-last is unsupported, the paragraph remains centered through the text-align declaration.

Testing Recommendations

Test last-line alignment with justified text, single-line paragraphs, forced line breaks, right-to-left content, and different container widths.

Specifications

The text-align-last property is defined in the CSS Text Module Level 3 specification.

CSS Text Module Level 3 - text-align-last Property

The specification defines last-line alignment, forced-break behavior, supported values, and interactions with general text alignment.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: text-align-last