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

FAQ accordion - HTML, CSS, JavaScript

accessibility
P
Aydan•680
@AydanKara
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?

āœ… Proud of:

  • Accessibility and Semantic Markup: I made sure to use semantic HTML elements (like <section>, <article>, <h2>, and <button>) along with ARIA attributes to create an inclusive experience.
  • Interactive and Smooth Transitions: Implementing the CSS transition for expanding and collapsing the FAQ sections really enhanced the user experience.
  • Dynamic Icon Updates: Updating the icon (switching from plus to minus) with descriptive alt text provided clear visual and accessible feedback on the accordion's state.

šŸ”„ What would I do differently next time?:

  • Dynamic Height Calculation: Instead of using a fixed maximum height for the accordion content transition, I would implement a dynamic calculation using JavaScript (e.g., setting max-height based on scrollHeight). This would make the solution more robust for varying content lengths.
What challenges did you encounter, and how did you overcome them?

šŸ—ļø Challenges:

  • Balancing Accessibility with Custom Interactions: Ensuring that the interactive elements (especially custom accordion buttons) remained accessible with clear ARIA attributes and keyboard support was a key challenge.

  • Smooth Transitions for Collapsible Content: Animating the height of an element whose content is dynamic (using height: auto) is inherently tricky, as CSS transitions don't work directly on auto values.

šŸŽ‰ How I Overcame Them:

  • āœ… Accessibility: I leveraged native elements (like <button>) to handle keyboard interactions and added ARIA properties to communicate the current state to assistive technologies. This minimized the need for custom keyboard event handling.
  • āœ… Transition Issue: I used a CSS trick with max-height and a predefined large value to simulate smooth transitions. Although this approach works, it highlighted the need for dynamic calculations, which is something to explore further in future iterations.
What specific areas of your project would you like help with?
  • Dynamic Height Calculation for Transitions: I would appreciate suggestions on how to implement a dynamic solution that calculates the actual height of the accordion content (using properties like scrollHeight) to create smoother and more adaptive transitions.

  • Code Refactoring: Feedback on structuring the JavaScript code in a more modular or scalable way would be beneficial. For instance, should I encapsulate the accordion behavior in a class or use a particular design pattern?

  • Cross-Browser Compatibility: Any insights or testing recommendations on ensuring that the CSS transitions and ARIA attributes work seamlessly across different browsers and devices would be valuable.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Aydan's solution.

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