Open In App

How to align the last line of a paragraph element to the right using CSS?

Last Updated : 30 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will set the alignment of last paragraph element to the right by using CSS property. To set the alignment of last paragraph to right, we use CSS text-align-last property.

The text-align-last is used to set the last line of the paragraph just before the line break. The line break may be due to the natural ending of a paragraph, or it may be due to the use of <br> tag. The text-align-last property sets the alignment of all the last lines occurring in the element in which the text-align-last property is applied. For example, if the text-align-last property is applied to the <p> element then, all the last lines of the <p> element will be affected by the text-align-last property.

Syntax:

text-align-last: right

Example:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>
        How to align last line of a
        paragraph element to the
        right using CSS?
    </title>
  
    <style>
        h1 {
            color: green;
        }
  
        p {
            text-align: justify;
            -moz-text-align-last: right;
            text-align-last: right;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h3>
        How to align last line of a
        paragraph <br>element to the
        right using CSS?
    </h3>
  
      
<p>
        Cascading Style Sheets, fondly referred
        to as CSS, is a simply designed language
        intended to simplify the process of making
        web pages presentable. CSS allows you to
        apply styles to web pages. More importantly,
        CSS enables you to do this independent of
        the HTML that makes up each web page.
    </p>
  
</body>
  
</html>


Output:

Supported Browsers: The browser supported by text-align-last property are listed below:

  • Google Chrome 47.0
  • Internet Explorer 5.5
  • Firefox 49.0, 12.0 -moz-
  • Opera 34.0


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads