Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS text-align-last Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 25 - Views
⏳ 4 mins
💬 1 Comment
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.

Syntax
Copied
Copy To Clipboard
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

ValueDescription
autoThe last line inherits the alignment value of the text-align property.
leftThe last line is aligned to the left.
rightThe last line is aligned to the right.
centerThe last line is centered.
justifyThe 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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy