Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Product preview card component using Flex

coinfilipā€¢ 130

@coinfilip

Desktop design screenshot for the Product preview card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Quite satisfying to finish this one, although conflicted whether adding images thru CSS instead of HTML tags will be helpful when it comes to accessibility. Please let me know of your thoughts, thank you.

Community feedback

@SadeeshaJayaweera

Posted

Adding images through CSS instead of HTML tags can have advantages and disadvantages, and it depends on the specific use case and context. Here are some considerations:

Advantages:

  1. Control Over Presentation: By using CSS to apply images as background images, you have more control over how the images are presented and styled. This can be useful for decorative or background images where the image is purely presentational and doesn't convey important content.

  2. Reduced HTML Bloat: If you have many decorative images, using CSS can help reduce the amount of HTML code, making your HTML cleaner and easier to maintain.

Disadvantages:

  1. Accessibility: The biggest drawback is accessibility. When you add images using HTML <img> tags, you can provide alt text, which is crucial for screen readers and users with disabilities. Alt text describes the image's content or purpose, making your content more accessible. When using CSS background images, there is no direct way to provide alt text, which can be a significant accessibility issue.

  2. Content Semantics: HTML is designed to provide semantic meaning to the content. Images are part of the content, and using HTML tags properly reflects this semantic structure. Using CSS for images can break the semantic structure of your content, making it less understandable for both users and search engines.

  3. Printing: If users want to print your webpage, CSS background images may not be included by default. This can lead to a poor user experience when trying to print content that relies on background images for presentation.

Recommendations:

  1. Use HTML for Content Images: For images that convey meaningful content or provide essential context to your web page, always use HTML <img> tags. Be sure to include descriptive alt text for accessibility.

  2. Use CSS for Decorative Images: If an image is purely decorative and doesn't convey essential information, then it's more appropriate to use CSS for styling. In such cases, make sure your HTML remains semantic and accessible, and the decorative image should not be vital for understanding the content.

  3. Consider Responsive Images: For responsive design, use the <img> element's srcset attribute to provide different image sizes for different screen resolutions and sizes. This ensures that your images adapt to different devices and screen sizes.

In summary, it's generally best to use HTML for content images and reserve CSS for styling and decorative images. Prioritize accessibility by providing proper alt text for all content images, and ensure that your web design is responsive to cater to various devices and screen sizes.

Marked as helpful

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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