<h3> Simple Accordion</h3>
<div class="accordion">
<details>
<summary><span>Step 1</span> Trip information <i></i> </summary>
<p>Trip type : One Way </p>
<p>From: Chennai </p>
<p>To: Dubai </p>
<p>Departure: 12 Aug,2020</p>
<p>Passengers count: 2</p>
<p>Return: </p>
</details>
<details>
<summary><span>Step 2</span>Flight information <i></i> </summary>
<p>Flight ID: </p>
<p>Flight name: </p>
<p>Flight Timings: </p>
<p>Seat status: </p>
</details>
<details>
<summary ><span>Step 3</span>Payment information <i></i></summary>
<p>Card type: </p>
<p>Card name: </p>
<p>Card Validity:</p>
<p>Payment status:</p>
</details>
</div>
This piece of code gives u a visual structure like the below.
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.
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.
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.