Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 2 years ago

Product preview card component using Flex

coinfilip•130
@coinfilip
A solution to the Product preview card component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

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.

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Sadeesha Jayaweera•240
    @SadeeshaJayaweera
    Posted almost 2 years ago

    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

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub