CSS text-align-last Property

CSS text-align-last property is used to align the last line of the text. The text can be aligned to the left, right, or center based on our requirements. See the example below:

Example:

.p1{
  text-align-last: right;
}
.p2{
  text-align-last: center;
}
.p3{
  text-align-last: justify;
}

Remember, If you apply the text-align-last property to an element and it has few child elements, this property will affect the last line of each and every child element.

For example: Suppose, you have a <div> element and it has three <p> elements inside it. Now, you apply the text-align-last: right; property to the <div> element. The last line of each paragraph will align to the right.

If you want only the very last line to be affected, you can use the :last-child selector. See the example below:

Example:

.div1{
  text-align-last: right;
}
.div2 p:last-child{
  text-align-last: right;
}

CSS Syntax

The text-align-last property has the following syntax:

text-align-last: auto|left|right|center|justify|start|end|initial|inherit;

Property Values

The text-align-last property accepts the following values:

autoThe last line of the text is aligned to match the text-align property. This means, if the text-align property is set to right, the last line will be aligned to the right. If the text-align property is not set, the last line will align to the start. This is the default value.
leftAligns the last line to the left.
rightAligns the last line to the right.
centerAligns the last line in the center.
justifyInserts white space between the words to cover the full width of the line.
startAligns the last line at the beginning based on the direction of the text. Aligns to the left if the direction is ltr and right if the direction is rtl.
endAligns the last line at the end based on the direction of the text. Aligns to the right if the direction is ltr and left if the direction is rtl.
initialSets the text-align-last property to its default value(auto).
inheritInherits the text-align-last property from the parent element.

General Info

Default Valueauto
InheritedYes
JavaScript Usageelement.style.textAlignLast = “center”

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.