Web application course html picture, video audio and hyperlink tag summary
Directory
- Web application course html picture, video audio and hyperlink tag summary
-
- Image tag
-
- Supported formats:
- Image loading error occurs
- some other properties
-
- hyperlink tag
- Related problem solutions
-
- 1. [Web Application Course Summary of HTML Basic Tags and Text Tags](https://www.acwing.com/solution/content/201345/)
- 2. [Web Application Course Forms, Lists, Tables, Semantic Tags, Summary of Special Symbol Tags](https://www.acwing.com/file_system/file/content/whole/index/content/9913246/)
Image tag
The element is an empty element in HTML, used to insert images (Image) into web pages.
The element is used to display images in web pages. It is a self-closing tag without a closing tag. Images can be embedded into HTML documents by specifying the image’s URL (src attribute).
Example:
<img src="path/to/image.jpg" alt="Description of the image">
In the above example, the src
attribute of the element specifies the URL of the image file, and the
alt
attribute gives a description or alternative to the image. text. Alternative text will be displayed to the user if the image fails to load or be read by a screen reader.
Note that to ensure web page accessibility, you should always provide a meaningful alternative text (via the alt
attribute) for the element, so that even if the image fails to load or Invisible to some users, it can also convey the information of the image.
To summarize, the element is used to insert images into HTML documents. It is a self-closing tag that specifies the URL of the image through the
src
attribute and provides the image’s alternative text through the alt
attribute.
Supported formats:
An image loading error occurred
If an error occurs while loading or rendering an image, and at least one onerror
event handler is set to handle the error
event, the set event handler will be called. Such errors can occur in a variety of different situations, including:
- The attribute value of the
src
attribute is empty (""
) ornull
. - The
URL
of thesrc
attribute is exactly the same as theURL
of the page the user is browsing. - The image is corrupted for some reason and won’t load.
- The image’s metadata is corrupted, its resolution/width and height cannot be retrieved, and there is no width/height specified in the element’s attributes.
- The format used by this image is not yet supported by the user agent.
Some other attributes
In addition to the src
and alt
attributes, the tag supports several other attributes that can be used to control the display and behavior of the image. Here are some commonly used
tag attributes:
- width and height: Specify the width and height of the image in pixels. Example:
<img src="image.jpg" width="300" height="200" alt="Image">
- title: Specifies the title of the image, which is displayed when the user hovers the mouse over the image. Example:
<img src="image.jpg" alt="Image" title="This is an image">
- loading: Specifies how the image is loaded. Can be set to
"eager"
(immediate loading),"lazy"
(lazy loading) or"auto"
(automatically determined by the browser, Defaults). Example:
<img src="image.jpg" alt="Image" loading="lazy">
- decoding: Specifies how the image is decoded. Can be set to
"sync"
(synchronous decoding) or"async"
(asynchronous decoding, default). Example:
<img src="image.jpg" alt="Image" decoding="async">
- sizes and srcset: used for responsive image display. The
sizes
attribute specifies the display size of the image under different viewport sizes, and thesrcset
attribute specifies image sources of different resolutions or sizes. Example:
<img src="image.jpg" alt="Image" sizes="(max-width: 600px) 100vw, 50vw" srcset="image.jpg 800w, image-2x.jpg 1600w">
- usemap: Define an image map (image map), used to map a certain area of the image to a link or other operation. Example:
<img src="image.jpg" alt="Image" usemap="#map">
Then define the