To add an image in HTML, use the <img>
tag with at least two essential
attributes: src
and alt
. The src
attribute specifies the path or URL to
the image file, while the alt
attribute provides alternative text that
describes the image for accessibility or when the image cannot be displayed.
Here is a simple example:
html
<img src="path-to-your-image.jpg" alt="Description of the image" width="500" height="300">
src="path-to-your-image.jpg"
tells the browser where to find the image.alt="Description of the image"
gives descriptive text for the image.- Optional attributes like
width
andheight
control the displayed size of the image.
The <img>
tag is self-closing and does not need a closing tag. If the image
is stored in a folder relative to your HTML file, the src
attribute should
include the folder path like src="images/photo.jpg"
. This method works for
local images uploaded to your website or images hosted externally by
specifying their full URL in src
. Adding images in HTML improves the visual
appeal and user experience of web pages. References:
- Use of
<img>
tag withsrc
andalt
attributes to embed images