- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
Master CSS text-align-last for Precise Text Alignment
Available options include left, right, center, justify, and more.
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 thetext-alignvalue, unless it’s set tojustify.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 thetext-alignvalue, unless it’s set tojustify.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’stext-alignproperty.
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-lastproperty 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:
| Browser | Version | Release Date |
|---|---|---|
| Google Chrome | 47.0 | December 2015 |
| Edge | 12.0 | - |
| Internet Explorer | 5.5 | July 2000 |
| Firefox | 49.0 | September 2016 |
| Opera | 34.0 | December 2015 |
| Safari | 16.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-lastproperty and other text-related CSS properties. - [MDN Web Docs]WebsiteUrl: Comprehensive documentation on the
text-align-lastproperty. - [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.
สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it’s done ที่แผนชัด งบไม่บานปลายแน่นอน
Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่
วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย
TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว
Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์
เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ! Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.