Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

HTML Tutorial

HTML HOME HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Styles HTML Project I HTML Formatting HTML Quotations HTML Comments HTML Colors HTML CSS HTML Project II HTML Links HTML Images HTML Favicon HTML Page Title HTML Tables HTML Lists HTML Project III HTML Block & Inline HTML Div HTML Classes HTML Id HTML Project IV HTML Global Attributes HTML Buttons HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Project V HTML Computercode HTML Semantics HTML Project VI HTML Dialog HTML Details HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Character Sets HTML Languages HTML URL Encoding HTML Performance HTML SEO

HTML Forms

HTML Forms HTML Form Attributes HTML Form Elements HTML Input Types HTML Input Attributes Input Form Attributes HTML Form Validation HTML Progress and Meter HTML Project VII

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Video HTML Audio HTML YouTube HTML Project VIII

Web Accessibility

Web Accessibility ARIA Attributes Keyboard Focus and tabindex Landmarks Skip Links Color Contrast

Web APIs

Web APIs Geolocation API Drag and Drop API Popover API Web Storage API Web Workers API Server-Sent Events API

HTML Cert

HTML Certificate

HTML Examples

HTML Examples HTML Videos HTML Editor HTML Quiz HTML Exercises HTML Challenges HTML Projects HTML Website HTML Syllabus HTML Study Plan HTML Interview Prep HTML Summary

HTML References

HTML Tag List HTML Attributes HTML Global Attributes HTML Browser Support HTML Event Attributes HTML Colors HTML Canvas HTML Audio/Video HTML Doctypes HTML Character Sets HTML URL Encode HTML Language Codes HTML Country Codes HTTP Status Codes HTTP Request Methods PX to EM Converter Keyboard Shortcuts

HTML Details and Summary


Share

HTML <details> Element

The HTML <details> element creates a box that the user can open and close.

The <summary> element is the visible title of the box.

The user clicks the title to show or hide the rest of the content.

The browser does all the work, so you do not need any JavaScript.

Details boxes are often used for:

  • questions and answers (FAQ)
  • extra information that not every reader needs
  • long content that you want to keep short at first

Example

A details box with a title. Click the title to open and close it:

<details>
  <summary>What is HTML?</summary>
  <p>HTML is the standard language for creating web pages.</p>
</details>
Try it Yourself »

How it Works

  • The <details> element holds all the content. Only the title shows at first
  • The <summary> element must be the first child of <details>
  • The browser adds a small triangle in front of the title. It points down when the box is open

Note: If you leave out the <summary> element, the browser shows the word "Details" as the title.



Open by Default

A details box is closed when the page loads.

Add the open attribute to show the content from the start:

Example

<details open>
  <summary>What is HTML?</summary>
  <p>HTML is the standard language for creating web pages.</p>
</details>
Try it Yourself »

The user can still close the box.


Create an Accordion

An accordion is a list of boxes where only one box is open at a time.

Give several <details> elements the same name attribute.

When the user opens one box, the browser closes the others:

Example

<details name="faq">
  <summary>What is HTML?</summary>
  <p>HTML is the standard language for creating web pages.</p>
</details>

<details name="faq">
  <summary>What is CSS?</summary>
  <p>CSS describes how HTML elements look on the screen.</p>
</details>

<details name="faq">
  <summary>What is JavaScript?</summary>
  <p>JavaScript makes web pages interactive.</p>
</details>
Try it Yourself »

Note: The name attribute on <details> is new.

In older browsers, the boxes still work, but more than one box can be open at the same time.


Styling Details and Summary

You can style <details> and <summary> with CSS, just like any other element.

The details[open] selector styles the box only when it is open:

Example

details {
  border: 1px solid #cccccc;
  border-radius: 5px;
  padding: 8px 16px;
  margin-bottom: 8px;
}

summary {
  font-weight: bold;
  cursor: pointer;
}

details[open] {
  background-color: #f1f1f1;
}
Try it Yourself »

Style the Triangle

The triangle in front of the title is a marker, like the bullet in a list.

Use the CSS ::marker pseudo-element to change its color:

Example

summary::marker {
  color: #04AA6D;
}
Try it Yourself »

Accessibility

A details box works with the keyboard by itself.

Users can move to the title with Tab, and open or close the box with Enter or Space.

Screen readers tell the user if the box is open or closed.

Keep the title short and clear, so users know what is inside before they open it.

Tip: Do not put links or buttons inside <summary>.

A click on them would also open or close the box, which confuses users.


Use <details> or <dialog>?

Both elements show and hide content, but they are made for different jobs.

The dialog element is explained in the HTML Dialog chapter.

  <details> <dialog>
Where the content shows In the page, right under the title In a box on top of the page
Needs JavaScript No Optional
Blocks the page No Yes, when opened with showModal()
Good for FAQs, extra information, long content Questions the user must answer, forms, warnings

Summary

  • <details> creates a box that the user can open and close
  • <summary> is the title of the box, and must come first
  • The open attribute shows the content when the page loads
  • Boxes with the same name work as an accordion

HTML Tag Reference

Tag Description
<details> Creates a box that the user can open and close
<summary> Defines the visible title of a <details> element

For a complete list of all available HTML tags, visit our HTML Tag Reference.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.