Tillitsdone
down Scroll to discover

Master CSS text-align-last for Precise Text Alignment

Learn how to use CSS text-align-last to control the alignment of the last line of text in a block.

Available options include left, right, center, justify, and more.
thumbnail

Introduction

The text-align-last property in CSS is a handy tool for web developers. It lets you control how the last line of text in a block or paragraph is aligned. This can help make your content look better and be easier to read.

Syntax

Using the text-align-last property is straightforward. Here’s how you do it:

text-align-last: auto;
text-align-last: start;
text-align-last: end;
text-align-last: left;
text-align-last: right;
text-align-last: center;
text-align-last: justify;
/* Global values */
text-align-last: inherit;
text-align-last: initial;
text-align-last: revert;
text-align-last: revert-layer;
text-align-last: unset;

Explanation:

  • auto: Aligns the last line based on the text-align value, unless it’s set to justify.
  • start: Aligns the last line to the left for left-to-right (LTR) text and to the right for right-to-left (RTL) text.
  • end: Aligns the last line to the right for LTR text and to the left for RTL text.
  • left: Aligns the last line to the left edge of the line box.
  • right: Aligns the last line to the right edge of the line box.
  • center: Centers the last line within the line box.
  • justify: Aligns the last line so it fits between the left and right edges of the paragraph.
  • inherit: Inherits the value from the parent element.
  • initial: Sets the value to its default.
  • revert: Resets the property to the browser’s default stylesheet.
  • revert-layer: Resets the property to the user-agent stylesheet.
  • unset: Resets the property to its inherited value if it inherits, or to its initial value if not.

Values

The text-align-last property offers several values to control the alignment of the last line of text in a block or paragraph.

auto

Aligns the last line based on the text-align value, unless it’s set to justify.

start

Aligns the last line to the left for LTR text and to the right for RTL text.

end

Aligns the last line to the right for LTR text and to the left for RTL text.

left

Aligns the last line to the left edge of the line box.

right

Aligns the last line to the right edge of the line box.

center

Centers the last line within the line box.

justify

Aligns the last line so it fits between the left and right edges of the paragraph.

initial

Sets the property to its default value.

inherit

Inherits the value from the parent element.

revert

Resets the property to the browser’s default stylesheet.

revert-layer

Resets the property to the user-agent stylesheet.

unset

Resets the property to its inherited value if it inherits, or to its initial value if not.

Formal Definition

The text-align-last property is formally defined to control the alignment of the last line of text within a block container.

Key Attributes:

  • Initial Value: auto
  • Applies to: Block containers
  • Inherited: Yes
  • Computed Value: As specified
  • Animation Type: Discrete

Formal Syntax:

text-align-last =
auto |
start |
end |
left |
right |
center |
justify |
match-parent;

Explanation:

  • auto: Aligns the last line based on the text-align value, unless it’s set to justify.
  • start: Aligns the last line to the left for LTR text and to the right for RTL text.
  • end: Aligns the last line to the right for LTR text and to the left for RTL text.
  • left: Aligns the last line to the left edge of the line box.
  • right: Aligns the last line to the right edge of the line box.
  • center: Centers the last line within the line box.
  • justify: Aligns the last line so it fits between the left and right edges of the paragraph.
  • match-parent: Aligns the last line based on the parent element’s text-align property.

Examples

Example: Justifying the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: justify;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line of the paragraph will be justified, ensuring that the text lines up with the left and right edges of the paragraph.

Example: Left Aligning the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: left;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line of the paragraph will be left-aligned.

Example: Right Aligning the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: right;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line of the paragraph will be right-aligned.

Example: Centering the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: center;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line of the paragraph will be centered.

Example: Using start for the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: start;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line will be aligned to the left for LTR text and to the right for RTL text.

Example: Using end for the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: end;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line will be aligned to the right for LTR text and to the left for RTL text.

Example: Using auto for the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: auto;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line will align based on the text-align value, unless it’s set to justify.

Example: Using initial for the Last Line

HTML

<p>
Prepare for the Recruitment drive of product-based companies like Microsoft, Amazon, Adobe, etc.,
with a free online placement preparation course. The course focuses on various MCQs & coding questions
likely to be asked in the interviews & make your upcoming placement season efficient and successful.
</p>

CSS

p {
text-align-last: initial;
font-family: sans-serif;
border: 1px solid black;
}

Result

The last line will be aligned according to its default value (left-aligned).

Example: Centered Last Line with Justified Text

HTML

<p>
Integer elementum massa at nulla placerat varius. Suspendisse in libero risus,
in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>

CSS

p {
font-size: 1.4em;
text-align: justify;
text-align-last: center;
}

Result

The last line of the paragraph will be centered, while the rest of the text remains justified.

Specifications

The text-align-last property is defined in the CSS Text Module Level 3 specification. This property specifies how the last line of a block or a line, right before a forced line break, is aligned.

Key Specifications:

  • Specification: [CSS Text Module Level 3]WebsiteUrl
  • Property Name: text-align-last
  • Description: The text-align-last property specifies how the last line of a block or a line, right before a forced line break, is aligned.

Browser Compatibility

The text-align-last property is supported by various browsers, although support may vary. Here’s a quick overview:

Supported Browsers:

  • Google Chrome: Supported in version 47.0 and later.
  • Edge: Supported in version 12.0 and later.
  • Internet Explorer: Supported in version 5.5 and later.
  • Firefox: Supported in version 49.0 and later.
  • Opera: Supported in version 34.0 and later.
  • Safari: Supported in version 16.0 and later.

Browser Compatibility Table:

BrowserVersionRelease Date
Google Chrome47.0December 2015
Edge12.0-
Internet Explorer5.5July 2000
Firefox49.0September 2016
Opera34.0December 2015
Safari16.0-

For the most up-to-date information, check the [Browser Compatibility Data (BCD)]WebsiteUrl.

See Also

If you found the text-align-last property useful, you might also be interested in these related CSS properties:

  • [text-align]WebsiteUrl: This property specifies the horizontal alignment of text within a block-level element.
  • [text-decoration]WebsiteUrl: This property allows you to add decorations to text, such as underlines, overlines, or line-through effects.
  • [direction]WebsiteUrl: This property specifies the text direction for a block-level element.

Additional Resources:

  • [CSS Text Module Level 3]WebsiteUrl: Detailed information about the text-align-last property and other text-related CSS properties.
  • [MDN Web Docs]WebsiteUrl: Comprehensive documentation on the text-align-last property.
  • [HTML Reference Guide]WebsiteUrl: A guide to HTML elements and attributes.

Further Reading:

  • [CSS Flexbox Guide]WebsiteUrl: Learn about advanced layout techniques using the Flexbox layout model.
  • [CSS Grid Layout Guide]WebsiteUrl: Explore the basics and advanced techniques of using the Grid layout model.
icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.