Images are an integral part of modern web design. They can be used for logos, illustrations, product images, and more. In HTML, images are inserted using the <img> element, which requires the src attribute to specify the image source (URL).
Syntax to add Image:
To add an image to your HTML document, use the following syntax:
<img src="image-url.jpg" alt="Image Description">
Image Attributes.
- src attribute contains the URL of the image file.
- alt attribute provides alternative text that is displayed if the image cannot be loaded.
- width and height use to Set the dimensions of the image.
- title attributes display a tooltip when the user hovers over the image.
Example: Adding Image to HTML.
<!DOCTYPE html> <html> <head> <title>Adding Images</title> </head> <body> <h1>Welcome to our Website</h1> <img src="images/logo.png" alt="Company Logo" width="200" height="100"> <p>Explore our products and services.</p> </body> </html>
Relative Path Vs Absolute Path.
- Relative Paths: Specify the path relative to the current HTML file.
- Absolute Paths: Provide the complete URL of the image.
<!-- Relative Path --> <img src="images/pic.jpg" alt="Picture"> <!-- Absolute Path --> <img src="https://example.com/images/pic.jpg" alt="Picture">
Trends is an amazing magazine Blogger theme that is easy to customize and change to fit your needs.