We help IT Professionals succeed at work.

how to center an image

472 Views
Last Modified: 2013-12-25
Hi
I want to center an image . Here is part of my code :

<body>
test
<div><img src="image.jpg"  align="center"> </div>
</div>

It is always on the left. I want the image in the center of my html page.

Thanks for your help
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2015

Commented:
You could try this, but it may affect other elements on the page.

<body style="margin:0 auto;padding:0;">
test
<div><img src="image.jpg"  align="center"> </div>
</div>
Greg AlexanderLead Developer

Commented:
try this

<div style="width: 50%; margin: auto;"><img src="image.jpg"></div>

Open in new window

Commented:
Maybe for kicks and giggles....
   Add :
align to the div:
<body style="margin:0 auto;padding:0;">
test
<div align="center"><img src="image.jpg"  align="center"> </div>
</div>
Paul SauvéRetired
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
oh and btw - I built a head and closed the body and head in my test, just to make sure it was reading it proper.  Just FYI.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.