We often use the CSS ‘text-align: justify;’ when justifying text, but this does not work for text that is only one line long. So this article explains how to deal with such cases.
How to use ‘text-align-last: justify;’
If ‘text-align: justify;’ does not work for a single line of text, you can solve the problem by using ‘text-align-last: justify;’ instead.
<p style="text-align: justify; text-align-last: justify;">
This is a single line of text, but the entire text is aligned.
</p>
As shown above, using ‘text-align-last: justify;’ will cause the text to be aligned on both ends, even on the last line. This can be applied to single lines of text as well as the last line of a paragraph.
However, the ‘text-align-last’ property is not supported by some older browsers, in which case you should consider other methods. We recommend that you always use the latest browser and check the compatibility of your web pages.