Images are powerful visual tools on websites. HTML allows us to display them with very simple syntax, but it’s important to understand how all related attributes work.
To insert images, we use the <img> element. It’s a self-closing tag that must include at least the src and alt attributes.
html
<img src="https://via.placeholder.com/150" alt="Example image">
The alt (alternative text) attribute describes the image for cases where it doesn't load or when the user relies on a screen reader. Always provide a meaningful and concise description.
You can use images stored within your project, not just external ones. For example, if you have a folder named 'images', you can access them like this:
html
<img src="images/logo.png" alt="Company logo">
The width and height attributes control image size. You can use pixels or percentages. It’s important to maintain the aspect ratio.
html
<img src="photo.jpg" alt="Photo" width="300" height="200">
The title attribute is useful for showing a tooltip when the cursor hovers over the image.
html
<img src="image.jpg" alt="Description" title="This is an image">
CSS makes it easy to resize images. To make an image fit the width of its parent container, you can use the following setting:
html
<img src="photo.jpg" alt="Resized image" style="width: 100%; height: auto;">
There are various image formats for different use cases. JPG is good for photos, PNG supports transparency, GIF handles animations, and WebP is a modern, compressed, fast-loading format.
Always make sure that images serve more than just a decorative purpose — they should contribute to the content as well. Using the alt attribute is crucial for user experience and accessibility.
Select Language
Set theme
© 2025 ReadyTools. All rights reserved.