How to align the text of the last paragraph line (#tilPost)

Today I learned there’s a CSS property to align the last line of a rendered paragraph – text-align-last. 😲
Initially, I couldn’t see the value of this property because the last paragraph line always follows the overall text-align pr…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Today I learned there's a CSS property to align the last line of a rendered paragraph – text-align-last. 😲

Initially, I couldn't see the value of this property because the last paragraph line always follows the overall text-align property. If your text is left-aligned, the last line is left-aligned, too. The same applies to center and right.

So, what's the deal?

A use case for text-align-last

After researching the topic, I discovered that the property can be helpful with text-align: justify. As discussed in a Tailwind issue, you can't style paragraphs with justified text and control the alignment of the last line without an additional CSS property.

With a combination of text-align and text-align-last this layout becomes possible.

p {
  text-align: justify;
}

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

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

Justifying text might look good to you and your designer, but be aware that irregular text spacing fails the WCAG success criterion 1.4.8.

It's cool that the property supports logical values like start and end. These values react to the reading direction. Suppose you build a multilingual site that includes right-to-left and left-to-right languages. Using start and end makes the last line alignment react to the text direction. Sweet!

[Interactive component: visit the article to see it...]

text-align-last browser support

So, how's the text-align-last browser support? 👇

MDN Compat Data (source)
Browser support info for text-align-last
chrome chrome_android edge firefox firefox_android safari safari_ios samsunginternet_android webview_android
47 47 12 49 49 Nein 5.0 47

And even though a WebKit ticket claims there's a prefixed property -webkit-text-align-last, it doesn't seem to work in Safari 15.4.

Conclusion

If the only use case of this property is in combination with text-align: justify, I'm very skeptical about it. Web performance and accessibility are close to my heart, so I haven't implemented justified text for ages.

Nevertheless, it's good to know that text-align-last exists. I guess... 🤷‍♂️


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2022-03-19T23:00:00+00:00) How to align the text of the last paragraph line (#tilPost). Retrieved from https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/

MLA
" » How to align the text of the last paragraph line (#tilPost)." Stefan Judis | Sciencx - Saturday March 19, 2022, https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/
HARVARD
Stefan Judis | Sciencx Saturday March 19, 2022 » How to align the text of the last paragraph line (#tilPost)., viewed ,<https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » How to align the text of the last paragraph line (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/
CHICAGO
" » How to align the text of the last paragraph line (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/
IEEE
" » How to align the text of the last paragraph line (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/. [Accessed: ]
rf:citation
» How to align the text of the last paragraph line (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2022/03/19/how-to-align-the-text-of-the-last-paragraph-line-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.