1. The ![]()
Element
In HTML, images are embedded using the self-closing element. Images are not inserted into the HTML document itself; instead, the browser fetches the image file from the specified path and renders it inline.
2. The Essential alt Attribute
The alt (alternative text) attribute is mandatory for standard-compliant HTML:
- Accessibility: Screen readers read the
altdescription to visually impaired students. - Network Failure: If the image fails to load (broken URL or weak cellular connection), the browser displays the
alttext in its place. - Search Engine Optimization (SEO): Web crawlers (Googlebot) index image content based on the
altattribute.
3. Specifying width and height for Layout Stability
Always specify the native dimensions (or aspect ratio) of images in HTML. This reserves physical space before the image downloads, completely eliminating Cumulative Layout Shift (CLS)—a critical Google Core Web Vital metric.
4. Native Lazy Loading with loading="lazy"
Modern browsers natively support deferred loading for off-screen images. By adding loading="lazy", the browser waits until the user scrolls close to the image before making network requests, dramatically boosting initial page load speeds: