Search code examples
htmlcsstext-alignmenttext-aligntext-justify

Justify text not working after breaking line


I have the align-text: justify; property applied to some text. The problem is when I want to move a word to a new line, the text is not justified. How can I fix this problem?

image

<div style="width: 400px; height: 200px;">
<p style="text-align: justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit <br>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>


Solution

  • You could try to add white-space: pre-line; and text-align-last: justify; to your code.

    <div style="width: 400px; height: 200px;">
    <p style="text-align: justify; white-space: pre-line; text-align-last: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit <br>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>