HTML align Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The align attribute sets horizontal alignment of an element (or, on images, how it sits beside text). Classic text values are left, center, right, and justify.

It appeared on many presentational tags (<p>, headings, table cells, <img>, <hr>, and more). For new work, use CSS: text-align, float, and vertical-align.

Deprecated.

Do not use align in new pages. Prefer CSS. Browsers still support it for old content — learn it to read legacy HTML, not to ship it.

HTML Syntax

syntax.html
<element align=" left | center | right | justify">

Images historically also used top, middle, and bottom (see values below).

Attribute Values

Common values and their modern CSS replacements:

ValueDescriptionTry it
leftFlush left text, or float image left. Prefer text-align: left / float: leftTry it
centerCenter text or content. Prefer text-align: centerTry it
rightFlush right text, or float image right. Prefer text-align: right / float: rightTry it
justifyStretch lines to both edges. Prefer text-align: justifyTry it
top / middle / bottomLegacy <img> vertical alignment. Prefer vertical-alignTry it

Live Preview

Toggle the deprecated align attribute on a paragraph. Prefer CSS in real projects.

Legacy demo only. New pages should use text-align instead.

Paragraph

The quick brown fox jumps over the lazy dog. Alignment changes the edges of these lines.

align="center" — prefer text-align: center

HTML Examples

Legacy snippets for study, plus the CSS replacement. Use Try It Yourself for a live editor.

Example 1 — Paragraph Alignment (Legacy)

How old pages centered a heading or paragraph.

HTML
<h1 align="center">How to Carve Wood</h1>
<p align="right">This paragraph hugs the right edge.</p>
<p align="justify">Justified text stretches to both margins when the line is long enough to wrap.</p>
Try It Yourself

How It Works

  1. align on the element sets that block’s text alignment.
  2. center / right / justify match the classic print meanings.
  3. Browsers still paint it for compatibility with old documents.
  4. Prefer CSS text-align with the same keywords in new code.

Example 2 — Image Float with align (Legacy)

On <img>, left / right wrapped text beside the image.

HTML
<p>
  <img src="/images/codetofun-logo.png" alt="CodeToFun logo" width="80" height="80" align="left">
  Text flows around an image aligned to the left. Prefer CSS float: left today.
</p>
Try It Yourself

How It Works

  1. align="left" on an image acts like floating left.
  2. Following text wraps beside the image.
  3. top / middle / bottom were vertical shortcuts — use vertical-align now.
  4. Always keep alt for accessibility (see alt).

Example 3 — Modern CSS Replacement

Same layout intent without the deprecated attribute.

HTML
<style>
  h1 {
    text-align: center;
  }
  p.note {
    text-align: right;
  }
</style>

<h1>How to Carve Wood</h1>
<p class="note">This paragraph hugs the right edge.</p>
Try It Yourself

How It Works

  1. text-align replaces text align values one-for-one.
  2. No presentational HTML — structure stays clean.
  3. Easier to maintain in stylesheets and responsive layouts.
  4. Use this pattern in every new project.

Edge Cases & Pitfalls

Treat align as historical — CSS always wins for new work.

deprecated

Not for new HTML

Validators and linters flag align. Replace it when you touch old templates.

CSS wins

text-align overrides the attribute

If both are set, CSS takes precedence. Prefer one source of truth: the stylesheet.

img

Image values differ from text

left/right float the image; top/middle/bottom adjust vertical alignment in a line.

char

align="char" was never reliable

Table alignment on a character was poorly supported. Do not depend on it.

email

Some email clients still use it

HTML email sometimes keeps presentational attributes. That does not make them good for websites.

Browser Support

align is a legacy HTML attribute. Engines still honor many values for compatibility, but it is deprecated in favor of CSS.

✓ Deprecated · Still parsed

align

Widely recognized in browsers for old documents. New sites should use text-align, float, and vertical-align instead.

Legacy Compatibility only
Google Chrome Legacy support
Supported*
Mozilla Firefox Legacy support
Supported*
Apple Safari Legacy support
Supported*
Microsoft Edge Legacy support
Supported*
Opera Legacy support
Supported*
Samsung Internet Legacy support
Supported*
Internet Explorer Full legacy support
Supported*
align Supported (deprecated)

Bottom line: *Supported for old pages — not recommended. Migrate to CSS when you can.

Key Takeaways

  • Role: presentational alignment — left, center, right, justify.
  • Status: deprecated — keep for reading legacy HTML only.
  • Replace with: text-align, float, vertical-align.
  • Images: left/right ≈ float; vertical values ≈ vertical-align.

One line: learn align for old markup — ship text-align (and friends) instead.

Frequently Asked Questions

It sets horizontal alignment of an element’s content or, on images, how the image sits beside text. Common values are left, center, right, and justify.
Yes. MDN and the HTML living standard treat it as deprecated. Prefer CSS text-align for text, float for image left/right wrapping, and vertical-align for inline image alignment.
Historically many presentational elements: p, div, h1–h6, table parts (tr, td, th), img, hr, iframe, and others listed in the HTML attribute reference.
Use CSS text-align: center on the element (or a parent).
Use CSS float: left (and clear floats as needed). For vertical position in a line of text, use vertical-align.
Yes for reading older pages and emails. Do not use it in new projects.

Next: alt

Provide alternative text when an image cannot be shown.

alt tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful