Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

HTML
HTML
0/10 completed
Beginner
Your first web pageText, links and imagesLists and tablesForms
Intermediate
Semantic HTMLAccessibility basicsSEO and meta tags
Advanced
Images, video and embedsModern HTML: dialog, details and more
Pro
Performance and best practices
Tracks / HTML / Advanced

Modern HTML: dialog, details and more

Things that used to need JavaScript libraries are now built into HTML: accordions, modals, popovers and autocomplete. Native versions are faster, more accessible and need less code.

Accordions with <details>

HTML · CSS · live preview
Preview

Giving <details> elements the same name makes them exclusive: opening one closes the others. They're keyboard-accessible, and their content can be found with Ctrl+F, with zero JavaScript.

Modals with <dialog>

HTML · CSS · live preview
Preview

With showModal() you get, for free:

  • Focus trapping inside the dialog
  • The Escape key to close it
  • A styleable ::backdrop
  • The rest of the page made inert

<form method="dialog"> closes the dialog when a button is clicked, and dialog.returnValue tells you which one.

Popovers: no JavaScript at all

HTML · CSS · live preview
Preview

The popover attribute gives you a layer on top of the page that closes when you click outside it or press Escape. It's perfect for menus, tooltips and toasts.

Autocomplete with <datalist>

HTML · CSS · live preview
Preview

Reusable markup with <template>

<template> holds HTML that isn't rendered until JavaScript clones it. It's great for lists built from data.

HTML · CSS · live preview
Preview

More useful elements and attributes

Feature What it does
<output> Displays the result of a calculation
inert attribute Makes a section non-interactive and invisible to assistive tech
hidden / hidden="until-found" Hide content (the second can be revealed by find-in-page)
enterkeyhint="send" Changes the mobile keyboard's Enter key label
contenteditable Makes any element editable
<search> Semantic wrapper for search forms
HTML · CSS · live preview
Preview

Practice

Build a "settings" page using only native HTML features:

  • An exclusive <details> accordion with 3 sections
  • A "Reset settings" button that opens a confirmation <dialog>
  • A help popover next to one setting
HTML · CSS · live preview
Preview
✎ Check your understanding

1.What does dialog.showModal() give you that a styled div doesn't?

2.How do you make several <details> elements behave as an accordion (only one open)?

← Images, video and embeds