Home  >  Article  >  Web Front-end  >  How to center the image in html

How to center the image in html

angryTom
angryTomOriginal
2020-03-02 11:30:3944011browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more