Skip to content
  • Learning paths
  • Challenges
  • Solutions
  • Articles
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 8 months ago

HTML & CSS Only

accessibility
P
Nate Valline•420
@nvalline
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'm pleased that I was able to complete the challenge to the design specifications while only using HTML and CSS.

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

I looked into animating the opening and closing of the `````` components, but was unable to achieve the results that I wanted.

What specific areas of your project would you like help with?

I would appreciate any suggestions for animating the `````` components or any other tips/suggestions to improve the quality of my code.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Julien Gilbert•500
    @juliengDev
    Posted 7 months ago

    Hi @nvalline, Hope you are doing fine

    Im going to try to anwser to the animation question you have.

    This how i approach the problem myself :

    1. I used CSS transitions for smooth animations, particularly on the max-height property.

    2. Instead of toggling a hidden attribute, I manipulated the max-height of the panel:

      • For closed panels: max-height: 0px
      • For open panels: max-height: panel.scrollHeight + "px"
    3. I added a CSS transition on the max-height property in our stylesheet:

      .accordion-panel {
        transition: max-height 0.3s ease-out;
        overflow: hidden;
      }
      
    4. In the JavaScript, I updated the toggleAccordion method to set the appropriate max-height:

      if (expand) {
        panel.style.maxHeight = panel.scrollHeight + "px";
      } else {
        panel.style.maxHeight = "0px";
      }
      
    5. I also added a visible class to control opacity for a fade-in effect:

      .accordion-panel {
        opacity: 0;
        transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
      }
      .accordion-panel.visible {
        opacity: 1;
      }
      

    This solution provides a smooth animation when opening and closing accordion panels, addressing the challenge mentioned in the review. It combines CSS transitions with JavaScript manipulation of element properties to achieve the desired effect without relying on complex libraries or excessive code.

    It might have another solution, but here is mine, hope it helps you to understand more the concept behind the effect.

    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

Oops! 😬

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

Log in with GitHub