In HTML, you can display images on a web page using the `<img>` element. The `<img>` element is a self-closing tag and does not require a closing tag. Here's an example of how you can add an image to an HTML page:
html
<img src="image.jpg" alt="Description of the image">
In the example above:
- The `src` attribute specifies the source (URL or file path) of the image.
- The `alt` attribute provides alternative text for the image. It is displayed if the image cannot be loaded or for accessibility purposes. It should describe the content or purpose of the image.
Here's an example with additional attributes:
html
<img src="image.jpg" alt="Description of the image" width="300" height="200">
In this example, we've added the `width` and `height` attributes to specify the dimensions of the image in pixels. It's generally recommended to specify both dimensions to prevent content shifting when the image loads.
You can use absolute or relative URLs in the `src` attribute to reference the image file. For example, `src="https://www.example.com/image.jpg"` for an absolute URL or `src="images/image.jpg"` for a relative URL within your project directory structure.
It's important to ensure that you have the necessary permissions or licenses to use the images on your web page, and to optimize images for web by resizing and compressing them to improve page load times.
Additionally, you can style images using CSS to control their position, size, borders, and other visual properties.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc