Home > Article > Web Front-end > How to load local images in html
Loading local images in HTML requires the use of the <img> tag. The steps are as follows: 1. Prepare the image and save it in the same directory as the HTML file; 2. Use the src attribute to specify the image path; 3. (Optional) Use the width and height attributes to specify the image size; 4. Use the alt attribute to set Image alt text.
How to load local images using HTML
Loading local images in HTML is a simple process, just Just use the <img>
tag. However, there are some points to note to ensure that the image displays correctly.
Steps:
Specify the image path:
Use the src
attribute to specify the path of the image, which should start from the location of the HTML file. For example:
<code class="html"><img src="image.jpg"></code>
Set the image size (optional):
Use the width
and height
properties to set The size of the image. If omitted, the image will be displayed at its original size.
<code class="html"><img src="image.jpg" width="200" height="150"></code>
Set image alt text:
Use the alt
attribute to provide alt text for the image to display when the image cannot be loaded.
<code class="html"><img src="image.jpg" alt="风景图片"></code>
Note:
Example:
<code class="html"><!DOCTYPE html> <html> <head> <title>加载本地图片</title> </head> <body> <img src="image.jpg" alt="风景图片"> </body> </html></code>
By following these steps, you can easily load local images in HTML.
The above is the detailed content of How to load local images in html. For more information, please follow other related articles on the PHP Chinese website!