LATEST >>

We Started A Facebook AutoLiker & AutoCommenter & GroupPoster. Check Out Our EXETools...

EXEIdeas – Let's Your Mind Rock » HTML Codes / HTML-CSS-PHP-JavaScript » How To Center An Image Or DIV To Horizontally Using HTML5?

How To Center An Image Or DIV To Horizontally Using HTML5?

How To Center An Image Or DIV Using HTML5?

If You Want To Center An Image Or A DIV In HTML File. You Have Two Ways To Place That In Center, One Is Simple And A HTML Tag But It’s Not Valid For HTML 5, As There Is A Major UpDate In HTML Version, So Many Of Professional WebMaster Are Leaving Old Style Because That Is Also Against Valid Rules And Give You Error If You Ty To Validate Your Code, So Use The New Code To Center It That Is A CSS Code. I Am Providing You Both Code And Now It’s UpTo You What You Use.

Use Any Method From The Following Methods To Center An Image Or A DIV, I Prefer To Use HTML5 Valid Syntax (Second Method). For This You Need To Add CSS Attributes To IMG Or DIV Tag. You Can Also Add Border To Image And Many Other Effects Using CSS With HTML. It Is Also Best For SEO Because After Many Updates In SEO, It’s Also A Targeted Factor For Better SEO.

Two Methods To Center Horizontally An Image In WebPage:

1.) Using Center Tag, This Is Not HTML5 Valid Syntax. But This Code Center An Image.

<center><img src="ImageURL" alt="Alt Text" title="Image Title" width="128" height="128"/></center>

2.) By Adding CSS Attribues Auto Margin And Block Display (Image Is An Inline Element Change It To Block Element). This Is HTML5 Valid Syntax.

<img style="margin:0px auto;display:block" src="ImageURL" alt="Alt Text" title="Image Title" width="128" height="128"/>

Two Methods To Center Horizontally A DIV In WebPage:

1.) Using Center Tag, This Is Not HTML5 Valid Syntax. But This Code Center An DIV.

<center><div>Your DIV Data</div></center>

2.) By Adding CSS Attribues Auto Margin And Block Display (Image Is An Inline Element Change It To Block Element). This Is HTML5 Valid Syntax.

<div style="margin:0px auto;display:block">Your DIV Data</div>

Conclusion:

No it’s up to you what you want to use to center your object, I am here only to clear the difference not to pressurize you, thanks for reading this, please leave your views and quires in the comment section.

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>