Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🚀 Days 11–15 – Pro Skills & Projects  ·  Day 11

Day 11: details, dialog, progress & data-*

⏱ 80 min📶 Intermediate🎯 100% self-study
Day 11 / 15

✅ Today you will learn

  • FAQ accordions with details/summary (zero JS)
  • Popups with dialog and popover
  • progress, meter, output and mark
  • Reusable markup with template
  • Store extra data with data-* attributes

🏢 In the real world

Sharma Sweets wants an FAQ section (“Is it eggless?”, “Do you deliver?”), a Diwali offer popup, a delivery-progress bar for bulk orders and product cards that remember price and weight. Many developers reach for a big JavaScript library – modern HTML does most of it on its own.

details & summary: an accordion with zero JavaScript

HTML
<style>details{border:1px solid #fcd9c8;border-radius:8px;padding:8px 12px;margin:6px 0;font-family:system-ui}
summary{cursor:pointer;font-weight:600;color:#9a3412}</style>
<details open>
  <summary>Are your sweets eggless?</summary>
  <p>Yes. All our mithai is 100% vegetarian and eggless, made in pure desi ghee.</p>
</details>
<details name="faq">
  <summary>Do you deliver outside Jaipur?</summary>
  <p>We ship dry sweets (kaju katli, soan papdi) across India in 3–5 days.</p>
</details>
<details name="faq">
  <summary>How long do they stay fresh?</summary>
  <p>Milk sweets: 2 days in the fridge. Dry sweets: up to 15 days.</p>
</details>
▶  Click a question – it opens and closes itself
💡 Exclusive accordion

Give several <details> the same name (as the last two above) and the browser keeps only one of them open at a time – supported in all modern browsers.

dialog: proper popups

HTML
<style>dialog{border:none;border-radius:12px;padding:20px;max-width:280px;font-family:system-ui;box-shadow:0 10px 40px #0004}
dialog::backdrop{background:#0006}</style>
<button type="button" onclick="offer.showModal()">🎁 See Diwali offer</button>
<dialog id="offer" aria-labelledby="ot">
  <h2 id="ot">Diwali Special 🪔</h2>
  <p>Flat 10% off on gift boxes above ₹2,000 till 1 November.</p>
  <form method="dialog"><button>Close</button></form>
</dialog>
▶  showModal(): focus is trapped inside; Esc closes it
FeatureWhat you get free
showModal()Dark backdrop, page behind is inert, focus moves inside
Esc keyCloses the dialog
<form method="dialog">Buttons inside close it without JS logic
::backdropStyle the dimmed background with CSS

popover

HTML
<button popovertarget="info">ℹ️ Ingredients</button>
<div id="info" popover style="padding:12px;border-radius:8px;font-family:system-ui">
  Cashew 60%, sugar 38%, ghee 2%, silver vark.
</div>
▶  popover + popovertarget: click outside or Esc closes it

progress, meter, output, mark

HTML
<div style="font-family:system-ui">
<p>Bulk order status: <progress value="3" max="5">3 of 5</progress> 3 / 5 steps (packing)</p>
<p>Uploading photo: <progress>loading…</progress> (no value = busy)</p>
<p>Box filled: <meter min="0" max="1" low="0.3" high="0.8" optimum="1" value="0.65">65%</meter> 65%</p>
<p>Shop rating: <meter min="0" max="5" value="4.6">4.6/5</meter> 4.6 / 5</p>
<form oninput="total.value = (+kg.value) * 900">
  <label>Kaju katli kg <input id="kg" type="number" value="2" min="1" style="width:60px"></label>
  = ₹<output name="total" for="kg">1800</output>
</form>
<p>Search result: Fresh <mark>ghewar</mark> available today.</p>
</div>
▶  Live bars and a calculator – change the kg

progress

  • Task completion over time
  • Order steps, uploads, quiz progress
  • No value = indeterminate spinner

meter

  • A measurement in a known range
  • Rating, storage used, stock level
  • low/high/optimum change the colour

data-* attributes and template

HTML
<style>.card{display:inline-block;border:1px solid #ddd;border-radius:8px;padding:8px;margin:4px;font-family:system-ui;cursor:pointer}
.card[data-stock="low"]{border-color:#e34f26}</style>
<div class="card" data-name="Kaju Katli" data-price="900" data-stock="low">Kaju Katli</div>
<div class="card" data-name="Ghewar" data-price="650" data-stock="ok">Ghewar</div>
<p id="out">Click a card…</p>
<script>
document.querySelectorAll('.card').forEach(function (c) {
  c.onclick = function () { out.textContent = c.dataset.name + ': ₹' + c.dataset.price + '/kg, stock ' + c.dataset.stock; };
});
</script>
▶  data-price is read by JS as element.dataset.price; CSS can style [data-stock="low"]
HTML
<ul id="list" style="font-family:system-ui"></ul>
<template id="row"><li><b class="n"></b> – ₹<span class="p"></span>/kg</li></template>
<script>
var sweets = [['Ladoo', 500], ['Rasmalai', 700], ['Ghewar', 650]];
sweets.forEach(function (s) {
  var li = row.content.cloneNode(true);
  li.querySelector('.n').textContent = s[0];
  li.querySelector('.p').textContent = s[1];
  list.appendChild(li);
});
</script>
▶  &lt;template&gt; is invisible markup that JS copies – perfect for repeated cards
🧠 Why this matters for the JS course

data-* and template are the bridge between HTML and JavaScript. In the JavaScript course you will build the full Sharma Sweets cart using exactly these.

🏅 Job skills unlocked today

✔ Build FAQ accordions with details/summary✔ Create accessible popups with dialog and popover✔ Show status with progress, meter and output✔ Store data in data-* and reuse markup with template

Practice tasks

🏋️ Practice – do it yourself

Task 1: Build a 3-question FAQ for home delivery where only one answer can be open at a time.
Show solution
HTML
<details name="d" open><summary>Minimum order?</summary><p>₹500 within 5 km.</p></details>
<details name="d"><summary>Delivery time?</summary><p>Within 2 hours, 9 am – 9 pm.</p></details>
<details name="d"><summary>Payment?</summary><p>UPI, cards or cash on delivery.</p></details>
▶  Result
Task 2: Make a “Book a tasting” button that opens a modal dialog with a small form (name, date) and a Cancel button.
Task 3: Show a loyalty card with <meter>: 7 of 10 visits complete.

Quick quiz

🧠 Quick Quiz – test yourself

1. Which element creates an accordion without JS?
Native toggle.
2. Which method opens a dialog as a modal?
show() opens non-modal.
3. A product rating 4.2/5 is best shown with…
A measurement in a range.
4. data-price="900" is read in JS as…
dataset maps data-* names.
5. Content inside <template> is…
Inert markup.

Interview corner

💼 Interview Corner

Why prefer <dialog> over a div-based modal?

dialog with showModal() gives correct role, focus management, Esc to close, an inert background and a ::backdrop – all of which are easy to get wrong when hand-built with divs.

What are data attributes used for?

To store custom, non-visible data on elements (IDs, prices, states) that JavaScript reads via dataset and CSS can target with attribute selectors – without inventing invalid attributes.

Summary

  • details/summary = accordion; same name = only one open.
  • dialog.showModal() and popover give accessible popups.
  • progress for tasks, meter for measurements, output for results.
  • data-* stores extra data; template holds reusable markup.
➡️ Next

Day 12: graphics and embeds – inline SVG icons, a canvas drawing, and safely embedding Google Maps and YouTube with iframe.

Frequently Asked Questions

Is details/summary good for SEO?
Yes – the hidden text is still in the HTML and is indexed. Add FAQPage schema (Day 9) for extra visibility.
Do I still need JavaScript?
For simple toggles and popups, no. For carts, fetching data and complex logic, yes – that is the JS course.
← HTML (15 Days)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicDay 12: SVG, Canvas & iframes Your progress: 11 / 15 (73%) · Lesson 12 / 15 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free