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).
Related Posts
- CSS: Align Center – Center Align Texts or Images in HTML and CSS
- Correct (CSS) way to center a page element in HTML
- CSS: Align Left – Make text or image aligned left with CSS
- CSS: Align Right – Make text or image aligned right in HTML page
- CSS: How to align HTML input checkbox and radio with text on the same line?
