Support0

CSS text-align-last playground

Explore text-align-last with controls for text direction and the alignment of the final line or the line before a forced break.

Ask AI

CSS text-align-last playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.

BaselineLab compares text-align-last in a justified paragraph so changes to the last line are easy to see.
This manual break also shows how the line before the br aligns within the same text block.
The last line follows the value you select.

HTML
<p class="text-align-last-sample" dir="ltr">
  BaselineLab compares text-align-last in a justified paragraph so changes to the last line are easy to see.<br>
  This manual break also shows how the line before the br aligns within the same text block.<br>
  The last line follows the value you select.
</p>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<p class="max-w-xl text-lg leading-7 text-justify [text-align-last:auto]" dir="ltr">
  BaselineLab compares text-align-last in a justified paragraph so changes to the last line are easy to see.<br>
  This manual break also shows how the line before the br aligns within the same text block.<br>
  The last line follows the value you select.
</p>
CSS
.text-align-last-sample {
  max-inline-size: 36rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  text-align: justify;
  text-align-last: auto;
}

Educational guide to text-align-last

Choose how each text block ends

Align the final line and lines before a forced break. Compare auto with explicit values and keep a consistent reading direction.

Mental model

text-align-last determines the alignment of a block’s last line and the line before a forced break, such as br. Other lines follow text-align. It does not select the last word or position the box in the layout.

  1. Soft wrap

    A line fills up and the text continues on the next because space runs out. That break does not turn the preceding line into a last line.

  2. Forced break

    A br ends the line even if space remains. That line receives text-align-last and the remaining text continues inside the same block.

  3. End of the block

    The line where the paragraph ends also receives the property. If the whole paragraph fits on one line, that single line is the last.

Static diagram of line endingsThe property acts on actual lines in the typeset text. Changing width can change the words on the last line, while an explicit break remains.

auto and paragraph alignment

auto does not always mean start. It follows text-align, except with justify, where it uses start. An explicit value such as center or end can change the last line even when the rest of the paragraph uses another alignment.

One paragraph, four ways to finish

text-align: center · text-align-last: auto

The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.

text-align: justify · text-align-last: auto

The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.

text-align: justify · text-align-last: center

The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.

text-align: justify · text-align-last: justify

The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.

With center/auto, every line is centered; with justify/auto, the last aligns to the start. justify/center centers only the last line and justify/justify also distributes its space. The borders show the available width, not a guarantee of good readability.
One paragraph, four ways to finish
<div class="text-align-last-guide-auto" lang="en">
  <div>
    <p class="label">text-align: center · text-align-last: auto</p>
    <p class="sample center-auto">The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.</p>
  </div>
  <div>
    <p class="label">text-align: justify · text-align-last: auto</p>
    <p class="sample justify-auto">The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.</p>
  </div>
  <div>
    <p class="label">text-align: justify · text-align-last: center</p>
    <p class="sample justify-center">The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.</p>
  </div>
  <div>
    <p class="label">text-align: justify · text-align-last: justify</p>
    <p class="sample justify-all">The available width determines where the lines of this paragraph wrap. The general alignment stays in place until the end of the block. Compare how the reading ends with an automatic, centered, or justified value. A short ending.</p>
  </div>
</div>
.text-align-last-guide-auto {
  display: grid;
  gap: 1rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    max-inline-size: 32ch;
    margin: 0;
    border: 1px solid currentColor;
    font-size: 1.25rem;
    line-height: 1.6;
  }

  .sample {
    text-wrap: wrap;
    hyphens: auto;
  }

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

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

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

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

You can use the property without justifying the paragraph. The playground keeps text-align: justify to make comparison easier, not because it is required. Justifying a short last line can create excessive gaps; keep auto or start for prose when a different ending is not needed. hyphens: auto uses the declared language and an available dictionary, without guaranteeing hyphens.

Soft wrapping and forced breaks

A br creates another affected ending inside the same paragraph. Wrapping to fit the available width does not. With preserved white space, a newline in the content can also be forced; in normal HTML, a newline in the source usually collapses to a space.

The same text with an added br

Soft wrapping only · text-align-last: end

The browser wraps this paragraph to the available width. Some breaks appear when the window changes, but this stretch of text ends here. A short ending.

A br before the ending · text-align-last: end

The browser wraps this paragraph to the available width. Some breaks appear when the window changes, but this stretch of text ends here.
A short ending.

In the first paragraph, end affects only the final line. In the second it also end-aligns the line before br; lines wrapping before that remain justified. The short phrase after the break is itself the block’s last line.
The same text with an added br
<div class="text-align-last-guide-breaks" lang="en">
  <div>
    <p class="label">Soft wrapping only · text-align-last: end</p>
    <p class="sample">The browser wraps this paragraph to the available width. Some breaks appear when the window changes, but this stretch of text ends here. A short ending.</p>
  </div>
  <div>
    <p class="label">A br before the ending · text-align-last: end</p>
    <p class="sample">The browser wraps this paragraph to the available width. Some breaks appear when the window changes, but this stretch of text ends here.<br>A short ending.</p>
  </div>
</div>
.text-align-last-guide-breaks {
  display: grid;
  gap: 1rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    max-inline-size: 32ch;
    margin: 0;
    border: 1px solid currentColor;
    font-size: 1.25rem;
    line-height: 1.6;
  }

  .sample {
    text-align: justify;
    text-align-last: end;
    text-wrap: wrap;
    hyphens: auto;
  }
}

Use br when the break belongs to the content, such as a verse or postal address. Do not add it to preserve a composition that only works at one width. The property inherits: on a container, it can affect the last line of every descendant paragraph, rather than just the last paragraph. Limit the selector to the block you want to treat.

Start and end follow direction

start and end follow the block’s direction. In horizontal LTR writing, start is left and end is right; in RTL they swap. left and right keep their physical sides. Language through lang and direction through dir are different data.

A single line has an ending too

dir="ltr" · text-align-last: start

Read to the end

dir="ltr" · text-align-last: end

Read to the end

dir="rtl" · text-align-last: start

مرحبا بالعالم

dir="rtl" · text-align-last: end

مرحبا بالعالم

These samples use text-align: start, without justify. Each paragraph has a single line and text-align-last determines its alignment: start/end swap sides between LTR and Arabic RTL. The text keeps its characters and the Arabic sample declares lang="ar".
A single line has an ending too
<div class="text-align-last-guide-direction">
  <div>
    <p class="label">dir="ltr" · text-align-last: start</p>
    <p class="sample start" lang="en" dir="ltr">Read to the end</p>
  </div>
  <div>
    <p class="label">dir="ltr" · text-align-last: end</p>
    <p class="sample end" lang="en" dir="ltr">Read to the end</p>
  </div>
  <div>
    <p class="label">dir="rtl" · text-align-last: start</p>
    <p class="sample start" lang="ar" dir="rtl">مرحبا بالعالم</p>
  </div>
  <div>
    <p class="label">dir="rtl" · text-align-last: end</p>
    <p class="sample end" lang="ar" dir="rtl">مرحبا بالعالم</p>
  </div>
</div>
.text-align-last-guide-direction {
  display: grid;
  gap: 1rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    max-inline-size: 32ch;
    margin: 0;
    border: 1px solid currentColor;
    font-size: 1.25rem;
    line-height: 1.6;
  }

  .sample {
    text-align: start;
  }

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

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

Alignment does not reverse reading order or center the block inside its parent. To choose general alignment, understand inline content and boxes, or compare justification methods, continue with the text-align guide linked below.

Common pitfalls

auto does not put the last line on the left

Expected result
The ending follows the declared alignment and direction.
Cause
auto follows text-align, with the exception of justify; start also depends on dir and does not always mean left.
Solution
Check both properties and dir. Use start to follow reading direction, or a physical side only when that is the intent.

An intermediate line changes too

Expected result
Only block endings or lines before a forced break change.
Cause
There is a br or a preserved newline; the property is not limited to the paragraph’s final visible line.
Solution
Check the HTML and white-space. Remove breaks added just to match a screenshot and allow natural reflow.

The ending is spaced too widely

Expected result
Words keep a readable rhythm at several widths.
Cause
text-align-last: justify distributes a short line’s space across only a few justification opportunities.
Solution
Return to auto or start and check enlarged text. Do not insert extra spaces to simulate alignment or force justification as a guarantee of readability.

Support and compatibility

text-align-last is Baseline Widely Available since September 2022. The playground’s seven values have established support. Compatibility is independent of text-justify and does not imply support for every part of the current drafts’ syntax.

In an older browser that ignores the declaration, the paragraph keeps normal text-align alignment without this adjustment to endings. The scenes use native CSS, need no JavaScript, and allow text to grow and wrap. Check the actual fonts, language, hyphenation, and width before reusing a justified composition.