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.

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/logo-tid.svg Latest Blogs
Discover our top articles, selected to support the growth of your business.
https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R43_Sep_1440x697.jpg@webp สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it&#8217;s done ที่แผนชัด งบไม่บานปลายแน่นอน https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R42_Sep_1440x697.jpg@webp Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่ https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R41_Sep_1440x697.jpg@webp วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R38_Sep_1440x697.jpg@webp TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R36_Sep_1440x697.jpg@webp Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์ https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R27_Sep_1440x697.jpg@webp เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ!
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
down Explore our best articles, cover a wide variety of technologies
Our knowledge base
196 Articles
Explore right
icons/logo-react.svg ReactJs
Popular JavaScript library for building user interfaces with a component-based architecture.
160 Articles
Explore right
icons/flutter.svg Flutter
UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.
144 Articles
Explore right
icons/logo-nodejs.svg Nodejs
JavaScript runtime for building scalable, high-performance server-side applications.
58 Articles
Explore right
icons/next-js.svg Nextjs
React framework enabling server-side rendering and static site generation for optimized performance.
38 Articles
Explore right
icons/tailwind.svg TailwindCSS
Utility-first CSS framework for rapid UI development.
36 Articles
Explore right
icons/code-outline.svg Typescript
Superset of JavaScript adding static types for improved code quality and maintainability.
126 Articles
Explore right
icons/code-outline.svg Golang
Programming language known for its simplicity, concurrency model, and performance.
67 Articles
Explore right
icons/code-outline.svg AstroJs
Astro is an all-in-one web framework. It includes everything you need to create a website, built-in.
38 Articles
Explore right
icons/code-outline.svg Jest
Versatile testing framework for JavaScript applications supporting various test types.
16 Articles
Explore right
icons/code-outline.svg Website development th
11 Articles
Explore right
icons/code-outline.svg Mobile application th
5 Articles
Explore right
icons/code-outline.svg Reactjs th
4 Articles
Explore right
icons/code-outline.svg Nextjs th
3 Articles
Explore right
icons/code-outline.svg Flutter th
1 Articles
Explore right
icons/code-outline.svg Software house th
1 Articles
Explore right
icons/code-outline.svg Nodejs th
1 Articles
Explore right
icons/code-outline.svg Typescript th
337 Articles
Explore right
icons/css-4.svg CSS
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
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
FacebookInstagramLinkedIn
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.