HTML Images
Learn how to display pictures and graphics on your web pages using the <img> tag.
What is an HTML Image?
HTML Images allow you to add visual content to your website. Images make websites more attractive and informative.
- Display photos, icons, or illustrations
- Enhance user engagement
- Support content visually for better understanding
Real-Life Example: Like pictures in books, images in websites help users understand content faster.
Common <img> Attributes
src– URL of the imagealt– Alternative text for accessibilitywidth– Width of the imageheight– Height of the imagetitle– Tooltip text when hoveringloading– Lazy loading withlazyoreager
HTML Image Examples
Example 1: Basic Image
<img src="logo.png" alt="CrackEase Company Logo">
Example 2: Image with Width and Height
<img src="banner.jpg" alt="Website Banner" width="600" height="200">
Example 3: Image with Tooltip
<img src="icon.png" alt="Settings Icon" title="Click to open settings">
Making Images Responsive
To make images adjust automatically on different screen sizes, use CSS with max-width and height: auto.
Example: Responsive Image CSS
<img src="banner.jpg" alt="Responsive Banner" class="responsive-img">
<style>
.responsive-img {
max-width: 100%;
height: auto;
}
</style>
Best Practices
- Always provide
alttext for accessibility - Use optimized images to reduce page load time
- Prefer modern formats like WebP for smaller size
- Make images responsive for all devices
- Use descriptive
titlefor better UX
Pro Tip: Well-optimized and accessible images improve SEO, UX, and website performance.