CSS text-align-last Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Typography

What You’ll Learn

The text-align-last property lets you align the final line of a text block differently from the rest of the paragraph — especially useful with justified text.

01

Last line

Final row only.

02

auto

Default mode.

03

justify pair

Fix ragged end.

04

left / right

Physical align.

05

center

Center finale.

06

text-align

Works with it.

Introduction

The text-align-last property in CSS is used to set the alignment of the last line of a text block or the line right before a forced line break.

This property is particularly useful for adjusting the text alignment in justified text blocks or for creating specific text alignment effects at the end of paragraphs.

Definition and Usage

Apply text-align-last on the same block element where you set text-align. It only changes the final line; earlier lines keep the main alignment.

A common pattern is text-align: justify; with text-align-last: left; or right; so the paragraph looks even except for a cleaner closing line.

💡
Beginner Tip

When a paragraph has only one line, that line is both the first and last line, so text-align-last affects it too.

📝 Syntax

The syntax for the text-align-last property is simple and follows the standard CSS property-value format:

syntax.css
element {
  text-align-last: value;
}

Here, value can be one of several predefined values that determine the alignment of the last line.

Basic Example

justify-last.css
p {
  text-align: justify;
  text-align-last: right;
}

Syntax Rules

  • Use it on block containers such as p, div, and table cells.
  • Pair it with text-align when you want different behavior on the final line.
  • auto makes the last line follow the element’s text-align value.
  • It also affects the line immediately before a forced break from <br>.

Related Properties

  • text-align — aligns all lines in the block
  • line-height — controls vertical spacing between lines
  • hyphens — can improve justified paragraph appearance

🎯 Default Value

The default value of the text-align-last property is auto. This means the alignment of the last line follows the alignment of the text block as a whole.

⚡ Quick Reference

QuestionAnswer
Default valueauto
Common valuesleft, right, center, justify
Best paired withtext-align: justify
Applies toBlock containers and table cells
InheritedYes
AnimatableNo

💎 Property Values

ValueExampleDescription
autotext-align-last: auto;The last line inherits the alignment value of the text-align property.
lefttext-align-last: left;The last line is aligned to the left.
righttext-align-last: right;The last line is aligned to the right.
centertext-align-last: center;The last line is centered.
justifytext-align-last: justify;The last line is justified, stretched so the line fills the full width.
auto left right center justify

When to Use text-align-last

text-align-last is most helpful when the final line needs different treatment:

  • Justified articles — Prevent an awkward stretched last line by setting text-align-last: left.
  • Formal layouts — Right-align the closing line of a justified paragraph for a editorial look.
  • Poetry or quotes — Center only the final line while keeping earlier lines left-aligned.
  • Forced breaks — Control alignment on the line before a <br> tag.

👀 Live Preview

Both paragraphs use text-align: justify. The second adds text-align-last: right so the final line aligns differently:

text-align-last: auto

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor.

text-align-last: right

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor.

Examples Gallery

Start with the reference justify + right-last-line example, then try left-last for cleaner justified text, centered closings, and a quote layout.

📜 Last Line Alignment

Align the last line of a paragraph differently from the rest — matching the reference example.

Example 1 — Justified text with a right-aligned last line

In this example, we’ll align the last line of a paragraph to the right while the rest of the paragraph is justified.

index.html
<style>
  p {
    text-align: justify;
    text-align-last: right;
  }
</style>

<p>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</p>
Try It Yourself

How It Works

text-align justifies every line by default, but text-align-last overrides alignment for the final line only.

Example 2 — Justified text with a left-aligned last line

Use text-align-last: left to avoid an overly stretched final line in justified paragraphs.

clean-justify.css
.article {
  text-align: justify;
  text-align-last: left;
}
Try It Yourself

How It Works

This is a common fix for justified body copy where the closing line has too few words.

📄 Typography Patterns

Use last-line alignment for quotes, signatures, and decorative text treatments.

Example 3 — Center the last line only

Keep body lines left-aligned while centering just the closing line for emphasis.

center-last.css
.closing-note {
  text-align: left;
  text-align-last: center;
}
Try It Yourself

How It Works

Only the last line uses the center alignment; previous lines follow text-align: left.

Example 4 — Quote block with a right-aligned signature line

Combine justified quote text with a right-aligned author line at the end.

quote-block.css
blockquote {
  text-align: justify;
  text-align-last: right;
  font-style: italic;
  border-left: 4px solid #2563eb;
  padding-left: 1rem;
}
Try It Yourself

How It Works

Put the author name in the same paragraph as the quote text so it becomes the last line and picks up text-align-last: right.

text-align-last in the family

text-align-last fine-tunes the final line after you set the main alignment with text-align. Use both together when you want justified paragraphs without an awkward closing line.

justify-pair.css
p {
  text-align: justify;
  text-align-last: left;
}

🧠 How text-align-last Works

1

text-align sets all lines

The block’s main alignment applies to every line, including left, center, right, or justify.

Base rule
2

text-align-last targets the finale

A separate keyword overrides alignment for the last line or the line before a forced break.

Override
3

auto follows text-align

With auto, the last line uses the same alignment as the rest of the block.

Default
=

Polished paragraph endings

Justified and multi-line blocks look cleaner with controlled last-line alignment.

Browser Compatibility

The text-align-last property is supported in most modern browsers, including current versions of Chrome, Firefox, Safari, Edge, and Opera. It is always a good practice to test your website across different browsers to ensure compatibility.

Modern browsers · Wide support

Reliable in current browsers

Chrome, Firefox, Edge, and Opera support text-align-last well. Safari added full support in recent versions.

94% Modern browser support
Google Chrome 47+ · Desktop & Mobile
Full support
Mozilla Firefox 49+ · Desktop & Mobile
Full support
Apple Safari 16+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 34+ · Modern versions
Full support

Testing tip

Compare justified paragraphs with and without text-align-last in Safari and Chrome to confirm the last line behaves as expected.

text-align-last property 94% supported

Bottom line: text-align-last is safe for modern projects, especially when paired with text-align: justify.

Conclusion

The text-align-last property is a handy tool for web developers looking to fine-tune the alignment of text within a block.

By customizing the alignment of the last line of text, you can achieve a more polished and professional look for your web content. Experiment with different alignment values to see how this property can enhance the readability and aesthetics of your web pages.

💡 Best Practices

✅ Do

  • Pair text-align-last with text-align: justify for cleaner paragraphs
  • Use left on the last line to fix stretched short closings
  • Test multi-line blocks in your target browsers
  • Keep author names or signatures on the last line when using right alignment
  • Remember that single-line paragraphs are affected too

❌ Don’t

  • Expect last-line control without setting text-align first
  • Use justify on very short paragraphs where last-line tweaks are unnecessary
  • Forget that forced <br> lines also count for this property
  • Hide important text in truncated last lines without an accessible alternative

Key Takeaways

Knowledge Unlocked

Five things to remember about text-align-last

Use these points when polishing paragraph alignment.

5
Core concepts
02

Last line

Final row only.

Scope
03

justify pair

Most common use.

Pattern
04

left / right

Clean endings.

Values
🔄 05

text-align

Set both together.

Companion

❓ Frequently Asked Questions

text-align-last sets the horizontal alignment of the last line in a block of text, or the line immediately before a forced line break.
text-align controls all lines in a block. text-align-last overrides the alignment for only the final line.
The default value is auto, which means the last line follows the text-align value of the element.
Justified paragraphs often stretch the last line awkwardly. text-align-last lets you left-align, right-align, or center just that final line for a cleaner look.
It applies to block containers and table cells that contain text, such as p, div, and td elements.

Practice in the Live Editor

Open the HTML editor and try text-align: justify; with text-align-last: right; on a paragraph.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful