How to Align Image in HTML?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

Image alignment is a technique for repositioning images on our web pages (top, bottom, right, left, and centre). We could align the image using the <img> align attribute or using CSS. In this article, we are going to see both methods of image alignment.

Align Image in HTML Using CSS

Center Alignment (horizontally center)

Set the left and right margins to auto and make the image into a block element to center it.

Output :

Center Alignment

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Middle Alignment (vertically center)

Set the vertical-align as middle.

Output :

Middle Alignment

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Top Alignment

Set the vertical-align as text-top.

Output :

Top Alignment

Bottom Alignment

Set the vertical-align as text-bottom.

Output :

Bottom Alignment

Left Alignment

Set the text-align as left.

Output :

Left Alignment

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Right Alignment

Set the float as right.

Output :

Right Alignment

Align Image in HTML Using the Align Attribute

The align attribute indicates how an image should be aligned concerning its container. To align the image, we use the align attribute. <img> element is an inline element. However, the align attribute has been deprecated since HTML4 as HTML is not meant for formatting. So you should always use CSS for image alignment.

Syntax :

Attribute ValuesDescription
leftIts purpose is to align the image to the left.
rightIts purpose is to align the image to the right.

Left Alignment

We Use the attribute value left to align the image to the left.

Output :

align image in html Using Left Alignment

Right Alignment

We use the attribute value right to align the image to the right.

Output :

align image in html Using right Alignment

Browser Support

BrowserVersion
Google Chrome38 and higher
Firefox38 and higher
Safari9.1 and higher
Microsoft Edge13 and higher
Internet Explorer10

Conclusion

  • We have looked at many examples of image alignment using CSS and the align attribute.
  • align attribute is not supported since HTML4, so we should always use CSS for image alignment.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more