← All elements

Horizontal Panel Accordion

by @admin · 0 views

<div class="hpa"><input type="radio" name="hpa" id="hpa1" checked><label for="hpa1" style="--c:#e11d48"><b>Plan</b><span>Sketch the idea before you write a line.</span></label><input type="radio" name="hpa" id="hpa2"><label for="hpa2" style="--c:#7c3aed"><b>Build</b><span>Small pieces, tested one at a time.</span></label><input type="radio" name="hpa" id="hpa3"><label for="hpa3" style="--c:#0f766e"><b>Ship</b><span>Release it, then watch how it is used.</span></label></div>

About this accordion

Three colour panels that stretch open sideways when selected, with the closed titles turned vertical.

How it works

Hidden radio inputs sit before their labels, and each label is a flex item. The checked panel gets a flex value of four while the others stay at one, so it stretches sideways. Its title rotates from vertical back to horizontal and the sentence fades in after a short delay.

Ways to customise it

  • Change the --c value on each label to recolour a panel.
  • Change flex: 4 for a wider or narrower open panel.
  • Add a fourth radio and label pair for another panel.

Good to know

Because the controls are radios, the arrow keys move between panels and a focus outline shows on the active one. Keep titles short, since closed panels are narrow on phones.

Open an example, copy the HTML and the CSS, and paste them into your page. There is nothing to install and no JavaScript to load.

More in Accordion

View all →