Open In App

Which HTML Attribute is used to justify the content ?

Improve
Improve
Like Article
Like
Save
Share
Report

The HTML attribute is used to justify-content is the align attribute. The align attribute of <p> tag is used to justify the text on a web page. This can be done by assigning the value to the aligned attribute as justified. The justification of the text aligns the text in such a way that it occupies equal horizontal space from both the left and right margins of a web page improving its appearance.

  • This attribute is applicable to various HTML elements, such as <p>, <img>, <table>, etc.
  • This align attribute determines the horizontal alignment of the content within its container.
  • This tag is outdated in HTML5.

Note: The align attribute is deprecated in HTML5, and styles should be used via CSS for better practices.

Syntax:

<p align="justify">

Example 1:

HTML
<!DOCTYPE html>
<html>

<head>
    <title>Not Justified</title>
</head>

<body>
    <h3>The content is not justified</h3>

    <p>
        Welcome to Geeks for Geeks. It is a 
        computer science portal for geeks.
        It contains well written, well 
        thought articles. We are learning 
        how to justify content on
        a web page. 
    </p>
</body>

</html>

Output:

Example 2:

HTML

<!DOCTYPE html>
<html>

<head>
    <title>Justified content</title>
</head>

<body>
    <h3>The content is justified</h3>

    <p align="justify">
        Welcome to Geeks for Geeks. It is 
        a computer science portal for geeks.
        It contains well written, well 
        thought articles. We are learning 
        how to justify content on
        a web page. 
    </p>
</body>

</html>

Output:

In this way align attribute is used to justify the content on the web page.


Last Updated : 12 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads