Interview Question

What is sizes attribute?

Sizes helps the browser choose from srcset correctly.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

The `sizes` attribute describes how wide a responsive image will appear. β€’ It is written inside an element’s opening tag. β€’ The HTML Standard limits which elements may use it and which values are valid. β€’ Browsers apply the attribute when they process the element or the resource it controls.

💡 Simple Example

<img srcset="small.jpg 480w, large.jpg 1200w" sizes="(max-width: 600px) 100vw, 600px" alt="Beach">

⚡ Quick Revision

Sizes helps the browser choose from srcset correctly.