HTML Images
Subject: html
HTML Images
Images are an essential part of modern web development, adding visual appeal, conveying information, and enhancing user engagement. In HTML, images are displayed using the <img> tag.
๐ผ๏ธ What is an HTML Image?
The <img> tag is used to embed images into a web page. It is a self-closing tag, meaning it does not require a separate closing tag.
Syntax:
src: Path or URL to the image filealt: Alternative text for accessibility and SEO
Example:
This displays an image with a specified width and height.
๐ Important <img> Attributes
src: Image path or URLalt: Alternative text for screen readers and fallbackwidth/height: Define dimensions (can also be styled via CSS)title: Tooltip shown on hoverloading="lazy": Defers loading until image is in view
โฟ Why Use the alt Attribute?
- Accessibility: Screen readers read alt text
- SEO: Helps search engines understand image context
- Fallback: Shown if image fails to load
๐ฑ Responsive Images with CSS
Use max-width and height: auto to ensure images scale properly:
๐ Linking Images
Make images clickable by wrapping them with <a>:
๐งพ Common Image Formats
- JPEG: Great for complex photos
- PNG: Supports transparency, ideal for logos
- GIF: For animations
- SVG: Scalable, ideal for logos and icons
๐ Lazy Loading
Improve performance with lazy loading:
๐จ Example: Styled Image with Internal CSS
โ Key Takeaways
- Use
<img>withsrcto embed images - Always include
alttext for accessibility and SEO - Use CSS or
width/heightattributes to control image size - Make images responsive with
max-width: 100% - Use
loading="lazy"to improve performance - Wrap with
<a>for clickable images
Advertisement Slot 1
Advertisement Slot 2