CSS Reference ยท Typography
The text-align-last property
Reference for the CSS text-align-last property: aligning or justifying the final line of a block, how it relates to text-align, with live examples.
The text-align-last property sets the alignment of the last line of a block, and of any line that comes right before a forced line break. By default the last line follows text-align, except that justify falls back to start for it. This property lets you choose something else, such as centering the last line of justified text, or justifying a single short line.
.quote { text-align: justify; text-align-last: center; }
Try it
A single line is also a "last line", so justify spreads the words across the full width.
Syntax
text-align-last: auto | start | end | left | right | center | justify;
- Initial value:
auto - Applies to: block containers
- Inherited: yes
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
The last line uses text-align; when that is justify, it uses start. |
start / end |
Aligns to the start or end edge of the line, following text direction. |
left / right |
Aligns to the physical left or right. |
center |
Centers the last line. |
justify |
Stretches the last line to fill the width. |
Usage notes
- Single-line blocks count. A block with one line has only a last line, so
text-align-lastfully decides its alignment. Combined withtext-align: justifyit is a quick way to spread short labels. - Forced breaks. A line that ends with a
<br>is also treated as a last line. - Justifying short lines looks odd. With few words, the gaps become very wide. Use it for headings and labels, not for sentences.
- Order of properties. If both are set,
text-align-lastwins for the last line;text-alignstill applies to all other lines. - Typical use. Centered last lines for pull quotes, or end-aligned signatures in justified letters.
Browser support
Supported in current versions of all major browsers; older Safari releases lacked it, so check a compatibility table if you must support them.
Related
text-alignโ aligns all other linestext-indentโ indents the first linehyphensโ reduces ugly gaps in justified text- Lesson: Styling Text