Aligning the Text in HTML 5

In HTML, you can align a text by using the ALIGN attribute and display the text according to your requirement on a Web page. The values of the ALIGN attribute are center, left, right, and justify. By default, the text appears left-aligned on the Web page. Below given briefly describes the values of the ALIGN attribute:

Attribute

Description

center

Aligns the whole text to the center of the Web page

left

Aligns the whole text to the left side of the Web page

right

Aligns the whole text to the right side of the Web page

justify

Justifies the whole text and also indents the first line

Let’s do the following steps to align the text:


<!DOCTYPE html>
<head>
<title>Aligning Text on Web Page </title>
</head>
<body>
    <h2 align=”center”>This text is aligned in the center</h2>
<h2 align=”left”>This text is aligned in the left</h2>
<h2 align=”right”>This text is aligned in the right</h2>
    <p align=”justify”> In HTML, you can align a text by using the ALIGN attribute and display the text according to your requirement on a Web page. The values of the ALIGN attribute are center, left, right, and justify. By default, the text appears left-aligned on the Web page. Below given briefly describes the values of the ALIGN attribute: </p>
</body>
</html> 

Save  the document with the name of CreatingAlignText.html. Open the HTML document in browser, it look like this:

This text is aligned in the center

This text is aligned in the left

This text is aligned in the right

In HTML, you can align a text by using the ALIGN attribute and display the text according to your requirement on a Web page. The values of the ALIGN attribute are center, left, right, and justify. By default, the text appears left-aligned on the Web page. Below given briefly describes the values of the ALIGN attribute:

Note: you can also use the <center> tag to align the text in the center of the Web page. This tag defines a region of the content to be centered.