Image: Simple accordion using <details> and <summary> tag.
Steps to acheive
Lets take a simple html structure like the below.
HTML:
This piece of code gives u a visual structure like the below.
Image: Simple html view
This is the basic of the entire concept. Clicking on the <summary> tag which holds the accordion title, will toggle the accordion content individually for each details tag.
They work independent of each other, unless it is handled by a script.
The <details> tag has the property to act like a toggle functionality for the contents other than the <summary> tag. This gives us n number of possibilites to create our desired UI functionality. And it is not restricted to just a accordion feature. In this example I've planned to use it as a check list for a train ticket booking system. Lets dive back in now.
Image: Click triggers the details tag to expand and reveal the contents inside
How it works?
On clicking the title of the <details>, ( which is actually the <summary> ), the browser returns the <details> with an attribute called open. This attribute plays the most part in styling the entire accordion.
Further to add to the visual clarity, I'm using font icons. Line Icons is my favourite, so I've used those.
Below is a formatted HTML with class names to differentiate active and completed steps.
HTML
Now comes the CSS part. This mostly revolves around the attribute part of the <details>.
CSS
This will give you the desired output as per the image below.
Now a further addition to the feature, to make the title of each section float on top while scrolling, we need to add a small piece. This is added to the summary tag in the css.