HTML Attributes
HTML align Attribute
The align attribute used to control horizontal alignment of elements, but it is deprecated in HTML5. Modern pages align content with CSS instead.
The align Attribute (Deprecated)
The align attribute is deprecated in HTML5 and must not be used in new code. Browsers may still honour it, but you should control alignment with CSS instead.
Historically, align set the horizontal (and sometimes vertical) positioning of content for elements such as <img>, <table>, <td>, <div>, <p> and headings. Values like left, right and center floated or aligned the element within its container.
Syntax (Legacy)
Legacy syntax: <element align="left|right|center|justify">. It is kept here only so you can recognise old markup — do not write it in new pages.
<!-- Deprecated: do not use -->
<img src="logo.png" align="right" alt="Company logo">
<p align="center">Centered text</p>Example
Run the modern replacement below — it uses CSS to achieve exactly what align once did, and is fully supported.
<!DOCTYPE html>
<html>
<body>
<img src="https://picsum.photos/id/1025/120/120"
alt="A dog resting" style="float: right; margin-left: 12px">
<p style="text-align: center">This paragraph is centered with CSS.</p>
<p style="text-align: justify">
This longer paragraph is justified with CSS text-align, spreading the
text evenly to both edges instead of relying on the old align attribute.
</p>
</body>
</html>More Examples
Centering a block element
<!DOCTYPE html>
<html>
<body>
<div style="width: 200px; margin: 0 auto; background: #eef; padding: 12px; text-align: center">
Centered box
</div>
</body>
</html>Attribute Values (and CSS Replacements)
| Old align value | Modern CSS equivalent |
|---|---|
| align="left" | text-align: left or float: left |
| align="right" | text-align: right or float: right |
| align="center" | text-align: center or margin: 0 auto |
| align="justify" | text-align: justify |
For centering block-level elements, use CSS such as margin: 0 auto or modern layout tools like Flexbox and Grid instead of the align attribute.
Key Takeaways
- align is deprecated in HTML5 — never use it in new code.
- It once controlled horizontal alignment on images, text and tables.
- Replace it with CSS text-align for text and float for images.
- Use margin: 0 auto, Flexbox or Grid to center block elements.
- CSS keeps presentation separate from structure, which is best practice.
