Search code examples
htmlcssword-wrapword-breaktext-styling

After word break, align next line to the left rather than center


I am styling my paragraphs and I have line break after a certain amount of characters. I want to be able to make the line after the break to be aligned left rather than center.

.justify {
  text-align: justify;
  text-justify: inter-word;
}

.paragraph {
  text-align: center;
  max-width: 220px;
  word-wrap: break-word;
  word-break: break-all;
}
<div class='justify'>
  <p class="paragraph">Hello, my name is Taylor and welcome to my personal website!</p>
</div>


Solution

  • You can use text-align-last

    The text-align-last CSS property describes how the last line of a block or a line, right before a forced line break, is aligned.

    MDN

    .justify {
      text-align: justify;
      text-justify: inter-word;
    }
    
    .paragraph {
      text-align: center;
      max-width: 220px;
      word-wrap: break-word;
      word-break: break-all;
      text-align-last: left;
      border: 1px solid red;
    }
    <div class='justify'>
      <p class="paragraph">Hello, my name is Taylor and welcome to my personal website!</p>
    </div>