Friday, December 20, 2024

HTML Images

 In HTML, you can display images using the <img> tag. Here's how you can use it:

Basic Syntax

<img src="path-to-image" alt="description">
  • src: Specifies the path to the image (this can be a URL or a file path).
  • alt: Provides alternative text for the image if it cannot be displayed (e.g., if the image is missing or the user has images disabled).

Example 1: Using a Local Image

<img src="images/picture.jpg" alt="A beautiful scenery">

Example 2: Using an Image from the Web

<img src="https://www.example.com/image.jpg" alt="A beautiful scenery">

Example 3: Specifying Width and Height

You can control the size of the image using the width and height attributes.

<img src="images/picture.jpg" alt="A beautiful scenery" width="300" height="200">

Example 4: Adding a Link to an Image

If you want the image to link to another page, you can wrap the <img> tag in an <a> tag.

<a href="https://www.example.com">
  <img src="images/picture.jpg" alt="A beautiful scenery">
</a>

Let me know if you'd like more examples!

No comments:

Post a Comment

How can you refer to a CSS file in a web page?

 To refer to a CSS file in a web page, you use the <link> element inside the <head> section of the HTML document. Here's t...