- 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:
Explanation:
auto
: Aligns the last line based on thetext-align
value, 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:
Explanation:
auto
: Aligns the last line based on thetext-align
value, 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-align
property.
Examples
Example: Justifying the Last Line
HTML
CSS
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
CSS
Result
The last line of the paragraph will be left-aligned.
Example: Right Aligning the Last Line
HTML
CSS
Result
The last line of the paragraph will be right-aligned.
Example: Centering the Last Line
HTML
CSS
Result
The last line of the paragraph will be centered.
Example: Using start
for the Last Line
HTML
CSS
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
CSS
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
CSS
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
CSS
Result
The last line will be aligned according to its default value (left-aligned).
Example: Centered Last Line with Justified Text
HTML
CSS
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:
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-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.
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.