👀 Live Preview
Three alignment values side by side:
Left-aligned text
Center-aligned text
Right-aligned text
Preview uses CSS text-align (the modern equivalent of align).

The align attribute in HTML is used to specify the horizontal alignment of content within various HTML elements. This attribute helps developers control the positioning of text, images, and other elements on a webpage.
Default text flow.
Centered content.
Push to the right.
Float-style layout.
Set align dynamically.
Modern best practice.
alignThe primary purpose of the align attribute is to determine the horizontal alignment of content within the designated HTML element. It can be applied to elements such as images, tables, and text, allowing developers to control the layout and presentation of their web pages.
The align attribute is not recommended for new projects. Browsers still render it, but CSS provides greater flexibility and is the standard approach today.
Add align to a supported element with a keyword value:
<p align="center">Centered text</p>left, center, or right.text-align, float, or flexbox.The align attribute accepts different values based on the HTML element it is applied to. Common values include:
<img src="photo.jpg" alt="Photo" align="left">
<p align="center">Centered paragraph</p>
<table align="right">...</table>| Value | Effect | CSS Alternative |
|---|---|---|
left | Align to the left edge | text-align: left or float: left |
center | Center horizontally | text-align: center |
right | Align to the right edge | text-align: right or float: right |
On <img> | Float-style text wrap | float: left/right |
On <table> | Position table in container | margin-left: auto (right align) |
| HTML5 status | Deprecated | Use CSS for new code |
| Element | Supported? | Notes |
|---|---|---|
<img> | Yes (legacy) | Text wraps around floated image |
<p>, <div> | Yes (legacy) | Horizontal text alignment |
<table> | Yes (legacy) | Positions table in container |
<hr> | Yes (legacy) | Aligns the horizontal rule |
| Modern HTML5 | Deprecated | Use CSS instead |
Left-aligned images, centered text, right-aligned tables, and dynamic JavaScript alignment.
Three alignment values side by side:
Left-aligned text
Center-aligned text
Right-aligned text
Preview uses CSS text-align (the modern equivalent of align).
Here’s an example of using the align attribute to left-align an image:
<img src="example.jpg" alt="Example Image" align="left">
<p>This text wraps around the image because the image is aligned to the left.</p>This code aligns the image to the left of its containing element. Surrounding text flows around the image on the right side, similar to a CSS float: left effect.
Here’s an example of using the align attribute to center-align paragraph text:
<p align="center">This text is centered.</p>The align attribute is applied to a paragraph element to center the text horizontally within its container.
Here’s an example of using the align attribute to right-align a table:
<table align="right">
<!-- Table content goes here -->
</table>In this example, the entire table is right-aligned within its container. Text and other content can flow beside it on the left.
You can dynamically set the align attribute using JavaScript to respond to user interactions or changes in the application state. Here’s a basic example:
<p id="dynamicElement">This paragraph will be centered dynamically.</p>
<script>
document.getElementById("dynamicElement").align = "center";
</script>In this script, the align attribute is set to center for an element with the id dynamicElement. This allows you to adjust the alignment dynamically based on specific conditions.
Choose left, center, or right in HTML or JavaScript.
Text aligns or images float based on element type.
Sibling content reflows around aligned elements.
For new projects, achieve the same result with CSS for maintainability.
The align attribute is deprecated in HTML5 but still rendered by all major browsers for backward compatibility with legacy pages.
Browsers honor align on legacy elements, but CSS is the modern standard.
Bottom line: Browsers still render align, but new code should use CSS text-align, flexbox, or grid.
text-align for text alignment in new projectsfloat or flexbox for image text-wrap layoutsalign when reading legacy HTML codebasesalign in new HTML5 documentsThe align attribute is a useful tool for controlling the horizontal alignment of content within HTML elements. While it can be effective for simple layouts, consider leveraging CSS for more advanced and responsive designs.
When maintaining older websites you may encounter align frequently. For anything new you build, reach for CSS—it gives you finer control and keeps your markup clean and standards-compliant.
alignBookmark these before aligning your next layout.
Three main values.
ValuesFloat-style wrap.
UsagePosition in container.
Usageelement.align
DynamicDeprecated in HTML5
Moderntext-align for text, float or flexbox for images, and margin: auto for block centering.img, p, div, table, hr, and others. All are legacy uses today.element.align = "center". For new code, prefer element.style.textAlign.Practice the align attribute with left, center, right, and JavaScript examples in the Try It editor.
5 people found this page helpful