Categories
CSS & HTML Tips

HTML: Center & Centering

While many still rely on HTML to center things or make page elements centered in the middle of the page, it’s actually the job of CSS.

In HTML, you can center things such as texts or images by using the CENTER tag:

<center>This is in the center of the page.</center>

You can center not only texts but also images:

<center><img src="photo.jpg" alt="" /></center>

However this may seem simple and straightforward, it’s not the correct way to do this. Accordingly to web standards, centering should be produced by CSS:

<div style="text-align:center"><img src="photo.jpg" alt="" /></div>

Notice the style attribute of the div tag, text-align:center prescribes that the inner image is centered in the center of the browser window (page).

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.