
Design comparison
Solution retrospective
✅ 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 onscrollHeight
). This would make the solution more robust for varying content lengths.
🏗️ 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.
-
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.
Community feedback
- @joshjavierPosted 9 days ago
Hi Aydan!
Good job on using semantic HTML elements and making accessibility a priority in your solution. 🤓👍
Here are some ideas you could apply in this solution or in future ones:
-
Setting a
max-height
cuts the content when viewed on mobile. In my case, I can only see four lines of text inside each accordion. You can fix this by implementing dynamic height transitions using CSS Grid. Check out Kevin Powell's video on the topic - it will blow your mind 🤯 -
In addition to toggling
aria-expanded
when the accordion button is pressed, you may also addaria-hidden
to the.accordion-content
container so that a closed accordion's content is not only hidden visually, but also to screen readers, thus providing a consistent user experience to everyone. You can read more about this topic here. -
For your icons, I suggest setting
aria-hidden="true"
andalt=""
. Why? Since the accordion button already contains text (the questions) then that effectively becomes the label of the button. Screen readers will also see thearia-expanded
attribute and let users know that they can expand or collapse the button, so no need to indicate this manually in the icon. For example, when I tested using VoiceOver in my iPhone, the second item reads:
Is Frontend Mentor free? Expand section. Button. Heading level 2 article. Landmark. Collapsed. Double-tap to expand.
Setting the icon to
aria-hidden="true"
andalt=""
will remove the "Expand section" phrase, leading to a more concise description.You can also look into inlining SVGs for your icons if you want to add simple transitions like animating a plus into a minus and vice versa. Save this article on accessible icon buttons and this video on inline SVGs for future reference!
Hope that helps. Happy coding!
Marked as helpful1 -
Please log in to post a comment
Log in with GitHubJoin 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