DEV Community

Raj
Raj

Posted on

HTML picture tag

Why do we use the tag?
We use the tag to display different images for different screen sizes. This helps improve website performance by loading the most suitable image for the user's device.

Why do we resize images?
If we use a large image, such as 1500px, and only shrink it with CSS, a mobile phone still downloads the full-size image. This makes the website slower and uses more internet data. Resizing images helps pages load faster.

**How do we use the tag?

Wrap the images inside a tag.
**
Add a tag for desktop or tablet (for example, min-width: 900px).

Add another tag for smaller devices (for example, min-width: 600px).

Finally, add an tag as the fallback image. If none of the conditions match, the browser displays the image.

This version sounds more like a real person explaining the concept in an interview, rather than reading from documentation.

Top comments (0)