Centering an Image in CSS

I have been working with some designs and I had to center an image in few pages. Previously I used to use <center> tag around the image tag and it works like a charm. But the <center> tag is deprecated in HTML5 and there is a beautiful way around to do this using CSS. Add the following code to make the image aligned exactly to the center of any web page.

img{
margin-left: auto;
margin-right: auto;
text-align: center;
}

This piece of code works like a charm.

Cheers,

SZ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s