HTML Images.
Images bring your content to life. Learning how to properly embed and optimize images is a core skill for any frontend developer.
The Essentials
The <img> tag is an 'empty' tag—it has no closing tag.
The 'src' attribute is required and specifies the path to the image.
The 'alt' attribute is required for accessibility and SEO.
The 'width' and 'height' attributes help the browser reserve space for the image.
You can use relative paths for local images or absolute URLs for web images.
Commonly used formats include JPG, PNG, GIF, and modern SVG or WebP.
Professional Insights
Why 'alt' Text is Mandatory
Aspect Ratio and Layout Shift
Responsive Images
The <figure> and <figcaption> Elements
Critical Pitfalls
Leaving out the 'alt' attribute entirely or using a useless value like 'image1'.
Uploading massive 5MB images when only a 200KB thumbnail is needed.
Forgetting to specify width and height, causing layout jumps during page load.
Using the wrong file format (e.g., using a non-transparent JPG when you need a transparent PNG logo).