HTML (Hypertext Markup Language) is one of the basic languages for creating Web pages. In web interface design, images are often used, so how to center images in HTML?
The following are 3 methods, implemented using CSS, HTML tables, and HTML5 tags respectively.
Method 1: Use CSS to center the image
You can use the margin property of CSS to center the image vertically and horizontally.
Steps:
img { display: block; margin: 0 auto; }
Explanation:
Method 2: Use HTML table to center the image
You can use the HTML table element and align attribute to achieve vertical and horizontal centering of the image.
Steps:
Explanation:
Method 3: Use HTML5 tags to center the image
HTML5 introduces some new semantic tags, such as