Home > Article > Web Front-end > How to center the image in html
htmlHow to center the picture
1. First, we need to create a new html page.
2. Then create a new img tag in the body part and specify an image.
3. Check the effect in the browser. You can find that the picture is left aligned by default and is not displayed in the center.
4. Wrap the image in a p or span tag, and add a style attribute with the value text-align:center to the tag.
Recommended learning: html tutorial
The code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p style="text-align: center;"> <img src="a.png" alt=""> </p> </body> </html>
For more HTML tutorials, please follow PHP Chinese website!
The above is the detailed content of How to center the image in html. For more information, please follow other related articles on the PHP Chinese website!