
Design comparison
Solution retrospective
Finding the right size for image, i used a pixel ruler which was 170px but for some reason when changing the image to 170px locally it was smaller than the design image - thus i increased image size.
What specific areas of your project would you like help with?how to find the correct size of desgin images without plug-and-chugging estimations
Community feedback
- @bhuvi819381Posted 3 months ago
Best Practices for HTML Image Tags
When working with
<img>
tags in HTML, it's essential to follow best practices to ensure accessibility and a responsive design. Below are some important recommendations:1. Always Provide an
alt
AttributeThe
alt
attribute serves as a text alternative when an image fails to load or for users relying on screen readers. Leaving thealt
attribute blank is not a good practice. Instead:- Provide a meaningful description of the image.
- If the image is purely decorative, you can still include an empty
alt
(i.e.,alt=""
) but ensure it is intentional.
Example:
<img src="example.jpg" alt="A scenic view of mountains at sunset">
2. Avoid Fixed
width
andheight
AttributesUsing fixed
width
andheight
attributes on images can lead to layout issues, especially on devices with varying screen sizes. Instead:- Use CSS to control image dimensions for a responsive design.
- Utilize the
max-width: 100%;
andheight: auto;
properties to make images scale appropriately.
Example:
<img src="example.jpg" alt="A scenic view of mountains at sunset" style="max-width: 100%; height: auto;">
Why These Practices Matter
- Accessibility: Ensuring images are accessible to all users, including those with visual impairments.
- SEO: Search engines use the
alt
text to understand the content of images. - Responsive Design: Avoiding fixed dimensions ensures a better user experience across devices.
By adhering to these guidelines, you can create more accessible and user-friendly websites.
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord