Table of contents
1.
Introduction
2.
Supported Tags
3.
Syntax
4.
Attribute Values
4.1.
Examples
4.1.1.
Example 1: Aligning a Paragraph
4.1.2.
Example 2: Aligning an Image
4.1.3.
Example 3: Aligning a Table
5.
Supported Browsers
6.
Frequently Asked Questions
6.1.
Why is the align attribute deprecated in HTML5? 
6.2.
Can I still use the align attribute in modern browsers? 
6.3.
What is the alternative to the align attribute in HTML5? 
7.
Conclusion
Last Updated: Jan 20, 2025
Easy

<Align> Tag in HTML

Author Sinki Kumari
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The align tag in HTML is used to control the alignment of elements like text, images, and tables. It plays a significant role in web design, helping developers organize content visually for better readability and structure. 

Align Tag in HTML

In this article, we will discuss the supported tags for alignment, their syntax, attribute values, examples, and browser compatibility. 

Supported Tags

The align attribute is commonly used with the following HTML tags:

  • <p> (paragraph)
     
  • <img> (image)
     
  • <table> (table)
     
  • <div> (division or section)
     
  • <h1>, <h2>, <h3> (heading levels)
     

While newer versions of HTML (HTML5) have largely replaced the align attribute with CSS properties, understanding its usage remains valuable for working on legacy projects.

Syntax

The general syntax for using the align attribute is straightforward and consistent across tags:

<tag align="value">
    Content goes here
</tag>

Attribute Values

The align attribute accepts different values depending on the tag it is applied to. Below are the most commonly used values:

  1. left: Aligns content to the left.
     
  2. right: Aligns content to the right.
     
  3. center: Aligns content to the center.
     
  4. justify: Aligns text to both the left and right margins (only for text-based tags like <p>).

Examples

Let’s explore how to use the align attribute with different tags.

Example 1: Aligning a Paragraph

Here’s how you can align text within a paragraph:

<!DOCTYPE html>
<html>
<head>
    <title>Paragraph Alignment</title>
</head>
<body>
    <p align="left">This paragraph is aligned to the left.</p>
    <p align="center">This paragraph is centered.</p>
    <p align="right">This paragraph is aligned to the right.</p>
    <p align="justify">This paragraph is justified to fit both left and right margins.</p>
</body>
</html>


Output:

Output
  • The first paragraph aligns to the left.
     
  • The second is centered.
     
  • The third aligns to the right.
     
  • The fourth is justified.

Example 2: Aligning an Image

You can align images within a page using the align attribute:

<!DOCTYPE html>
<html>
<head>
    <title>Image Alignment</title>
</head>
<body>
    <img src="example.jpg" alt="Example Image" align="left">
    <p>This text flows around the image aligned to the left.</p>


    <img src="example.jpg" alt="Example Image" align="right">
    <p>This text flows around the image aligned to the right.</p>
</body>
</html>


Output:

  • The first image is aligned to the left, with text wrapping around it.
     
  • The second image is aligned to the right, with text wrapping accordingly.

Example 3: Aligning a Table

The align attribute helps position tables within a page:

<!DOCTYPE html>
<html>
<head>
    <title>Table Alignment</title>
</head>
<body>
    <table align="center" border="1">
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
        <tr>
            <td>Data 1</td>
            <td>Data 2</td>
        </tr>
    </table>
</body>
</html>


Output:

Output

 
The table is centered on the page, with a border around it.

Supported Browsers

Most modern browsers like Google Chrome, Mozilla Firefox, Microsoft Edge, and Safari support the align attribute for backward compatibility. However, since it is deprecated in HTML5, it’s recommended to use CSS for alignment in new projects. For instance, you can achieve the same effect using:

p {
    text-align: center;
}

Frequently Asked Questions

Why is the align attribute deprecated in HTML5? 

The align attribute is deprecated in HTML5 because CSS provides more flexible and robust ways to handle alignment.

Can I still use the align attribute in modern browsers? 

Yes, modern browsers still support the align attribute for backward compatibility, but it’s better to use CSS for new projects.

What is the alternative to the align attribute in HTML5? 

The alternative is using CSS properties like text-align for text, float or margin for images, and margin or text-align for tables.

Conclusion

The align tag in HTML offers a simple way to control the alignment of various elements, making content more organized and visually appealing. Although it is deprecated in HTML5, understanding its usage is essential for maintaining or updating legacy projects. You can use this knowledge to align text, images, and tables effectively.

You can also check out our other blogs on Code360.

Live masterclass