Full Byte Developer.

6 UI parts that no longer need JavaScript

Native HTML handles accordions, modals, popovers, date pickers, color pickers, and form validation.

Published here · 4 sources

These six UI patterns used to require JavaScript libraries. Now they work with plain HTML.

1. Accordion (details and summary)

The details element expands and collapses content. Add the same name attribute to make only one open at a time [1] [2]:

html
<details name="faq">
  <summary>Question one</summary>
  <p>Answer one.</p>
</details>
<details name="faq">
  <summary>Question two</summary>
  <p>Answer two.</p>
</details>

You should see clickable summaries that expand to show their content.

2. Modal dialog

The dialog element with showModal() creates a modal with a backdrop. For a declarative open, use a form with method="dialog" [4]:

html
<dialog id="confirm">
  <p>Are you sure?</p>
  <form method="dialog">
    <button value="cancel">Cancel</button>
    <button value="confirm">Confirm</button>
  </form>
</dialog>
<button onclick="document.getElementById('confirm').showModal()">Open</button>

You should see a centered dialog with a dimmed backdrop when opened.

3. Popover (no modal)

The popover attribute creates a non-modal overlay. Use popovertarget on a button to toggle it without JavaScript [3]:

html
<button popovertarget="menu">Open menu</button>
<div id="menu" popover>
  <p>Menu content</p>
</div>

You should see the popover appear when clicked, and close when clicking outside.

4. Date picker

The date input type shows a native calendar picker on desktop and mobile:

html
<input type="date" name="start">

You should see a date picker when the field is focused.

5. Color picker

The color input type opens a native color selector:

html
<input type="color" name="theme" value="#3b82f6">

You should see a color swatch that opens a picker when clicked.

6. Form validation

Required fields, email format, and pattern matching work without JavaScript:

html
<form>
  <input type="email" required placeholder="Email">
  <input type="text" pattern="[0-9]{5}" placeholder="ZIP code">
  <button type="submit">Submit</button>
</form>

You should see browser validation messages when submitting invalid input.

Send this to the friend installing a JavaScript library just to build a modal or accordion.

Keep this guide

By Full Byte Developer

Filed under Dev tools

Questions about this guide

Do these work in all browsers?

Yes. The elements listed here have full support in Chrome, Firefox, Safari, and Edge as of 2024.

Can I style them?

Yes. Use CSS selectors like details[open], ::marker, and ::backdrop to customize appearance.

Sources

  1. MDN: details elementdeveloper.mozilla.org
  2. MDN: dialog elementdeveloper.mozilla.org

Next in this stack