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

Faq-accordion JS Challenge

@jeancy•230
@Jeancyjr
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?

This was a great project to challenge myself to start applying Javascript without tutorial.

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

I'm just starting with JS, so I only need to keep building, Which I'm doing daily.

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

    Hi

    As good as this looks on the surface, I’m afraid it is inaccessible and needs re-coding. It’s really important to get the HTML right so that components like this are accessible.

    This must follow an accordion (or disclosure) pattern. You can see all requirements for these ui patterns on the aria authoring practices guide. But essentially these must be opened using a button element that has aria-expanded on it correctly set. The icons also must be inside the button and have empty alt as they are decorative. The aria-expanded value is already communicating the expanded/collapsed state of the disclosure.

    Other pointers:

    • it's better for performance to link fonts in the html head instead of css imports.
    • don't forget to always include a full modern css reset at the start of the styles in every project. Andy Bell or Josh Comeau both have good ones you can look up and use.
    • the max width on the component should be in rem not px so it scales correctly for all users including those who have a different text size setting.
    • you should be coding mobile first and not using min and max media queries like this. Let the mobile styles be the default. Then set a min-width media query to target larger screens only. This should be defined in rem or em not px so that the layout adjusts nicely when people change their default text size. More info: https://fedmentor.dev/posts/responsive-meaning/
    • you don't need to repeat any style properties in a media query if they are unchanged from the default.
    • it would be better for performance to include the purple image in the html in a picture element instead of using background image. Users will currently have to download both images, whereas the picture element would only download the relevant one for their screen size.
    • try not to change inline styles with javascript. That can make sites very difficult to maintain. Keep concerns separate. Use JS to toggle classes or attributes and let css handle all styling. All that's needed in this is the aria-expanded value to change with javascript as you can use that attribute as the style hook in css to show/hide faq answers. Or if you prefer JS can toggle a class or data- attribute as well as aria-expanded and use that as the style hook instead.

    I hope this is helpful info.

    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

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.

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