CSS Properties
CSS text-align-last Property
Photo Credit to CodeToFun
🙋 Introduction
The text-align-last
property in CSS is used to set the alignment of the last line of a text block or the line right before a forced line break.
This property is particularly useful for adjusting the text alignment in justified text blocks or for creating specific text alignment effects at the end of paragraphs.
💡 Syntax
The syntax for the text-align-last
property is simple and follows the standard CSS property-value format.
element {
text-align-last: value;
}
Here, value can be one of several predefined values that determine the alignment of the last line.
🎛️ Default Value
The default value of the text-align-last
property is auto. This means the alignment of the last line follows the alignment of the text block as a whole.
🏠 Property Values
Value | Description |
---|---|
auto | The last line inherits the alignment value of the text-align property. |
left | The last line is aligned to the left. |
right | The last line is aligned to the right. |
center | The last line is centered. |
justify | The last line is justified, meaning it is stretched so that every line has equal width (like in newspapers and magazines). |
📄 Example
In this example, we'll align the last line of a paragraph to the right while the rest of the paragraph is justified.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS text-align-last Example</title>
<style>
p {
text-align: justify;
text-align-last: right;
}
</style>
</head>
<body>
<h1>Text-Align-Last Property Example</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa.
</p>
</body>
</html>
🖥️ Browser Compatibility
The text-align-last
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.
🎉 Conclusion
The text-align-last
property is a handy tool for web developers looking to fine-tune the alignment of text within a block.
By customizing the alignment of the last line of text, you can achieve a more polished and professional look for your web content. Experiment with different alignment values to see how this property can enhance the readability and aesthetics of your web pages.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS text-align-last Property), please comment here. I will help you immediately.