Hello there! In this lesson, we'll be exploring images - a crucial component of modern web pages. Images can enhance the visual appeal of your website, convey information, and engage your users. Let's dive into the world of images in HTML and learn how to embed and customize images effectively.
In HTML, images are embedded using the <img>
tag. The <img>
tag
is a self-closing tag, which means it doesn't have a closing tag. Here's
the basic structure of embedding an image in HTML:
<img src="image.jpg" alt="Description of the image">
In the code above, the <img>
tag is used to embed an image. The
"src" attribute specifies the source or URL of the image file. The "alt"
attribute provides alternative text for screen readers and when the
image cannot be displayed.
You can customize the appearance of images in HTML using attributes like width and height. These attributes allow you to control the dimensions of the displayed image. Here's an example:
<img src="image.jpg" alt="Description of the image" width="300" height="200">
In the code above, we added the "width" and "height" attributes to the<img>
tag. The values "300" and "200" specify the width and height
of the image in pixels, respectively. You can adjust these values to
control the size of the displayed image.
There are several ways to provide the source or URL of an image:
<img src="image.jpg">.
<img src="https://www.example.com/image.jpg">.
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/wAAg8AAVsRExPQAAAAASUVORK5CYII="
alt="Encoded image">.
You can also watch this video and learn how to upload images from your computer
Now, let's put your knowledge into practice! Open your code editor and create a new HTML file. Experiment with embedding images, providing different source options, and customizing their appearance. Here's a simple exercise to get you started:
<img>
tag. You can use an image file from your computer or a publicly available image on the web. For example,
<img src="image.jpg" alt="Beautiful sunset"
width="400" height="300">
<img src="image.jpg"
alt="Sunset over the ocean" width="500" height="400">
In this lesson, we've explored images in HTML, including how to embed images, provide different source options, customize their appearance using width and height attributes, and more. Images play a vital role in modern web design, enhancing the visual appeal and engagement of your website. Remember to use images wisely, follow best practices, and always test your images to ensure they display correctly on different devices and browsers. In the next lesson, we'll move on to HTML audio tutorial. Stay tuned, and happy coding!