HTML align Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Styling

Introduction

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.

What You’ll Learn

01

Left Align

Default text flow.

02

Center Align

Centered content.

03

Right Align

Push to the right.

04

Images & Tables

Float-style layout.

05

JavaScript

Set align dynamically.

06

Use CSS Instead

Modern best practice.

Purpose of align

The 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.

⚠️
Deprecated in HTML5

The align attribute is not recommended for new projects. Browsers still render it, but CSS provides greater flexibility and is the standard approach today.

📝 Syntax

Add align to a supported element with a keyword value:

align.html
<p align="center">Centered text</p>

Syntax Rules

  • Value is a keyword: typically left, center, or right.
  • Applied directly on the element being aligned (not on a wrapper in most cases).
  • Deprecated—prefer CSS text-align, float, or flexbox.
  • Behavior varies slightly by element type (text vs image vs table).

💎 Values

The align attribute accepts different values based on the HTML element it is applied to. Common values include:

  • left — Aligns the content to the left.
  • right — Aligns the content to the right.
  • center — Centers the content horizontally.
align-values.html
<img src="photo.jpg" alt="Photo" align="left">
<p align="center">Centered paragraph</p>
<table align="right">...</table>

⚡ Quick Reference

ValueEffectCSS Alternative
leftAlign to the left edgetext-align: left or float: left
centerCenter horizontallytext-align: center
rightAlign to the right edgetext-align: right or float: right
On <img>Float-style text wrapfloat: left/right
On <table>Position table in containermargin-left: auto (right align)
HTML5 statusDeprecatedUse CSS for new code

Applicable Elements

ElementSupported?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 HTML5DeprecatedUse CSS instead

Examples Gallery

Left-aligned images, centered text, right-aligned tables, and dynamic JavaScript alignment.

👀 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).

Example 1: Aligning Left

Here’s an example of using the align attribute to left-align an image:

align-left.html
<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>
Try It Yourself

How It Works

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.

Example 2: Aligning Center

Here’s an example of using the align attribute to center-align paragraph text:

align-center.html
<p align="center">This text is centered.</p>
Try It Yourself

How It Works

The align attribute is applied to a paragraph element to center the text horizontally within its container.

Example 3: Aligning Right

Here’s an example of using the align attribute to right-align a table:

align-right.html
<table align="right">
  <!-- Table content goes here -->
</table>
Try It Yourself

How It Works

In this example, the entire table is right-aligned within its container. Text and other content can flow beside it on the left.

Dynamic Values with JavaScript

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:

dynamic-align.html
<p id="dynamicElement">This paragraph will be centered dynamically.</p>

<script>
  document.getElementById("dynamicElement").align = "center";
</script>
Try It Yourself

How It Works

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.

♿ Accessibility

  • Alignment does not replace structure — Use headings and semantic HTML; do not rely on centering alone for hierarchy.
  • Avoid justified text for long paragraphs — Uneven spacing can reduce readability for some users.
  • Do not center critical instructions — Left-aligned body text is easier to scan for most readers.
  • Prefer CSS media queries — Responsive layouts adapt better than fixed HTML alignment attributes.

🧠 How align Works

1

Author sets align on element

Choose left, center, or right in HTML or JavaScript.

Markup
2

Browser applies layout rule

Text aligns or images float based on element type.

Rendering
3

Content shifts horizontally

Sibling content reflows around aligned elements.

Layout
=

Visual positioning achieved

For new projects, achieve the same result with CSS for maintainability.

Browser Support

The align attribute is deprecated in HTML5 but still rendered by all major browsers for backward compatibility with legacy pages.

Deprecated · Still supported

Legacy alignment attribute

Browsers honor align on legacy elements, but CSS is the modern standard.

99% Legacy support
Google Chrome Legacy support
Supported
Mozilla Firefox Legacy support
Supported
Apple Safari Legacy support
Supported
Microsoft Edge Legacy support
Supported
Internet Explorer Full legacy support
Supported
Opera Legacy support
Supported
align attribute (legacy) Deprecated — use CSS

Bottom line: Browsers still render align, but new code should use CSS text-align, flexbox, or grid.

💡 Best Practices

✅ Do

  • Use CSS text-align for text alignment in new projects
  • Use float or flexbox for image text-wrap layouts
  • Understand align when reading legacy HTML codebases
  • Test alignment on mobile—fixed HTML align does not adapt
  • Keep alignment consistent across your design system

❌ Don’t

  • Use align in new HTML5 documents
  • Mix inline align with conflicting CSS rules without testing
  • Center long blocks of body text (reduces readability)
  • Rely on align for responsive multi-column layouts
  • Forget that align is deprecated in the HTML specification

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about align

Bookmark these before aligning your next layout.

5
Core concepts
🖼 02

Images & Text

Float-style wrap.

Usage
📊 03

Tables

Position in container.

Usage
⚙️ 04

JavaScript

element.align

Dynamic
🎨 05

Use CSS

Deprecated in HTML5

Modern

❓ Frequently Asked Questions

It specifies horizontal alignment (left, center, or right) of content within an HTML element.
No. It is deprecated. Browsers still support it for legacy pages, but CSS is recommended for new code.
Use text-align for text, float or flexbox for images, and margin: auto for block centering.
Historically: img, p, div, table, hr, and others. All are legacy uses today.
Yes. Use element.align = "center". For new code, prefer element.style.textAlign.
Yes. All major browsers support it for backward compatibility, even though it is not part of modern HTML best practices.

Learn legacy and modern alignment

Practice the align attribute with left, center, right, and JavaScript examples in the Try It editor.

Try left-align example →

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.

5 people found this page helpful