2. Adding Images to Web Pages
Images can be embedded in a webpage via CSS, offering advantages such as responsive design adjustments. CSS can change an image's display properties based on the screen size, ensuring optimal layout across devices.
Image File Types
- .jpg: Small file sizes facilitate quicker loading times, ideal for photographs due to good color reproduction. However, quality may decrease when scaled up.
- .png: Known for supporting transparencies and maintaining color depth with high quality, but larger file sizes may slow down web loading times.
- .gif: Best suited for animations, offering small file sizes and sharp image quality. Though it supports transparency, it can result in a halo effect around images.
- .svg (Scalable Vector Graphics): Excellent for graphics that need to scale without loss of quality, such as logos and icons.
- .webp: Offers superior compression techniques, achieving high quality with smaller file sizes compared to jpg and png. Well-supported in modern browsers.
- .pdf: While not traditionally used for web images, PDFs are becoming more common for certain types of web content.
- .tiff: Once used in early web design, TIFF files are now impractical for web use due to their size.
Steps for Implementing an Image
- Determine the maximum display dimensions of the image.
- Use an image editor like Photoshop or a free alternative to create a canvas at the desired size.
- Insert the image onto the canvas and adjust its size appropriately.
- Save the image in the chosen format, considering the balance between quality and file size.
- Include the image in your HTML using the
<img>
tag or CSS, depending on the context and requirements for responsiveness. - For responsive design, use CSS to control the image's max-width and height properties, ensuring it scales properly across devices.
Steps for Getting an Image Ready for Web Use
- Edit the image to the largest needed size, considering the viewing context and device types.
- Save the image for the web, choosing a format that offers a good balance between quality and load time.
- Use tools or plugins within your image editing software to further optimize the image size without sacrificing quality.
- Test the image's load time on various devices and connections to ensure a good user experience.
Always store original, unedited image files separately for future editing needs.
To embed an image in your page:
- Determine the correct placement in your HTML code.
- Embed the image using the
<img>
tag, and then adjust its width and height for responsiveness. - Ensure the 'alt' attribute is descriptive and accessible, improving SEO and accessibility for users with visual impairments.
Example:
