Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 8 months ago

FAQ Accordion (without JavaScript)

sass/scss
P
Levi•230
@law973
A solution to the FAQ accordion challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I like how the background image scales, and how it switches from mobile to desktop displays via media queries. While I like trying to use transitions, I think an instant change works alright here.

Next time, I would try out making the accordion using JavaScript and/or making it more accessible.

What challenges did you encounter, and how did you overcome them?

On Safari, the desktop background image didn't scale properly. Using width: 100%, the image's width was fixed and did not respond to the viewport width. Using width: 100vw, the image's width was dynamic, but could not go beyond the width the viewport had whenever the page was loaded/refreshed.

To solve this problem, the div containing the background images was given a width of 100%, and the background images were set to inherit their widths:

.background__container {
  width: 100%;
}

.background__desktop, .background__mobile {
  width: inherit;
}
What specific areas of your project would you like help with?

I have a couple of questions:

  • What is the best way to implement the plus and minus sign SVGs? I tried to find a way to insert them as mask images using ::after on the summary elements, but I encountered a "CORS" error, and this method overall was unfamiliar to me. Should they have been added as images that have alt text (which is what I went with), or would the svg tag have been more appropriate?
  • Given the use of the details and summary tags, what are the best ways to make this solution more accessible?
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Grace•32,130
    @grace-snow
    Posted 8 months ago

    Those icons are decorative so must have empty alt.

    Alternatively you can see how to do it with inline svgs by just changing the rect inside an svg here: https://inclusive-components.design/collapsible-sections/

    The background images should also be treated as decorative.

    Definitely don't hide and show img elements like this. Use the picture element for those backgrounds. Much more performant.

    One more thing - lose those title attributes off the footer links. They are unnecessary, leading to duplicate screen reader announcements for some, and ignored by others.

    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 1st-party linked stylesheets, and styles within <style> tags.

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.

Frontend Mentor for Teams

Frontend Mentor for Teams helps companies and schools onboard and train developers through project-based learning. Our industry-standard projects give developers hands-on experience tackling real coding problems, helping them master their craft.

If you work in a company or are a student in a coding school, feel free to share Frontend Mentor for Teams with your manager or instructor, as they may use it to help with your coding education.

Learn more

Oops! 😬

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

Log in with GitHub