<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dr Hossam</title>
    <description>The latest articles on DEV Community by Dr Hossam (@dr_hossam_a6694b22e1451cc).</description>
    <link>https://dev.to/dr_hossam_a6694b22e1451cc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4236491%2F330ad384-44db-455c-a1e0-ea86c25967c1.jpg</url>
      <title>DEV Community: Dr Hossam</title>
      <link>https://dev.to/dr_hossam_a6694b22e1451cc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dr_hossam_a6694b22e1451cc"/>
    <language>en</language>
    <item>
      <title>What I learned building an accessible FAQ accordion as a beginner</title>
      <dc:creator>Dr Hossam</dc:creator>
      <pubDate>Wed, 18 Nov 2026 08:00:34 +0000</pubDate>
      <link>https://dev.to/dr_hossam_a6694b22e1451cc/what-i-learned-building-an-accessible-faq-accordion-as-a-beginner-44ip</link>
      <guid>https://dev.to/dr_hossam_a6694b22e1451cc/what-i-learned-building-an-accessible-faq-accordion-as-a-beginner-44ip</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2tznptk03vg9kuoeyk0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2tznptk03vg9kuoeyk0z.png" alt=" " width="800" height="370"&gt;&lt;/a&gt;I'm a veterinarian learning frontend development, and I'm building my portfolio with &lt;a href="https://www.frontendmentor.io" rel="noopener noreferrer"&gt;Frontend Mentor&lt;/a&gt; challenges. My latest one was an FAQ accordion with HTML, CSS and vanilla JavaScript.&lt;/p&gt;

&lt;p&gt;It looks simple, but I learned more from it than from my earlier projects. Here are the four lessons that stuck with me.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A &lt;code&gt;button&lt;/code&gt; inside an &lt;code&gt;h2&lt;/code&gt; is the right structure
&lt;/h2&gt;

&lt;p&gt;My first idea was to make the question a clickable &lt;code&gt;div&lt;/code&gt;. But a button gives you keyboard support (Tab, Enter, Space) for free, and the heading keeps the page structure meaningful for screen readers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;aria-expanded&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;aria-controls&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"faq-answer-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Is Frontend Mentor free?
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"faq-answer-1"&lt;/span&gt; &lt;span class="na"&gt;hidden&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Yes, many challenges are free.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;aria-controls&lt;/code&gt; connects the button to the answer by its &lt;code&gt;id&lt;/code&gt;, and &lt;code&gt;aria-expanded&lt;/code&gt; tells assistive technology if the answer is open or closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The &lt;code&gt;hidden&lt;/code&gt; attribute is a simple way to hide content
&lt;/h2&gt;

&lt;p&gt;Instead of adding and removing classes, I toggle one attribute in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"click"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aria-controls"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;isOpen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aria-expanded"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aria-expanded"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hidden&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Buttons don't inherit your font
&lt;/h2&gt;

&lt;p&gt;My questions looked huge and used a different font. Two reasons: browsers don't pass the page font to buttons, and my button was inside an &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt;, so it inherited the heading's big default size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.faq-question&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inherit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Test suggestions instead of trusting them
&lt;/h2&gt;

&lt;p&gt;My editor's AI suggested a version of the script that looked right, but it assumed the answer was the &lt;em&gt;next sibling&lt;/em&gt; of the button. Because my button sits inside an &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt;, that returned &lt;code&gt;null&lt;/code&gt; and crashed on the first click. Opening the browser console showed me the error right away.&lt;/p&gt;

&lt;p&gt;Small things like checking the Network tab for 404 errors (my fonts were not loading because of wrong paths) saved me a lot of time too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Live demo: &lt;a href="https://code-surgeon-hossam.github.io/faq-accordion/" rel="noopener noreferrer"&gt;https://code-surgeon-hossam.github.io/faq-accordion/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="https://github.com/Code-Surgeon-Hossam/faq-accordion" rel="noopener noreferrer"&gt;https://github.com/Code-Surgeon-Hossam/faq-accordion&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm working through more Frontend Mentor challenges and writing about what I learn. If you have tips for a beginner, or feedback on my accessibility choices, I'd love to hear them in the comments.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>html</category>
      <category>a11y</category>
    </item>
  </channel>
</rss>
