Home » HTML details & summary Tags Explained: Usage, Examples & Best Practices

HTML details & summary Tags Explained: Usage, Examples & Best Practices

Introduction

When building modern websites, improving user experience is just as important as adding content. One common UI pattern you see everywhere is expand/collapse sections—like FAQs, dropdowns, or hidden content.

In the past, developers needed JavaScript to create this behavior. But now, HTML provides a built-in solution using <details> and <summary>.

Learn basics: /html-basics

These tags allow you to create interactive, collapsible content without writing any JavaScript.

Think of <details> like a foldable box, and <summary> as the title you click to open it.

What are details & summary Tags?

The <details> tag creates a collapsible content section, while the <summary> tag defines the visible heading that users click to expand or collapse the content.


These tags work together:

  • <details> → Container for hidden content
  • <summary> → Clickable title

When the user clicks the summary, the content expands or collapses.

Learn semantic HTML: /semantic-html-guide

What are the <details> and <summary> tags in HTML?

The <details> tag creates collapsible content, and the <summary> tag provides the clickable title to show or hide it.

Basic Syntax of details & summary

Here is a simple details tag example:

<details>
  <summary>Click to view more</summary>
  <p>This is hidden content.</p>
</details>

Explanation (Line by Line)

  • <details> → Starts collapsible section
  • <summary> → Clickable heading
  • <p> → Hidden content
  • </details> → Ends the section

By default, the content is collapsed.

Where to Use details & summary

They are used to create collapsible sections such as FAQs, dropdowns, hidden content, and expandable information blocks.

These tags are very useful in real-world websites.

1. FAQ Sections

<details>
  <summary>What is HTML?</summary>
  <p>HTML is a markup language used to create web pages.</p>
</details>

2. Read More / Show Less

<details>
  <summary>Read more</summary>
  <p>Here is additional information...</p>
</details>

3. Product Details

<details>
  <summary>Product Specifications</summary>
  <p>Details about the product...</p>
</details>

4. Tutorials and Notes

<details>
  <summary>Tip</summary>
  <p>Practice coding daily.</p>
</details>

Real-World Examples

Let’s explore practical usage of the HTML details tag.

Example 1: FAQ Section

 
<section>
  <h2>FAQs</h2>

  <details>
    <summary>What is CSS?</summary>
    <p>CSS is used for styling web pages.</p>
  </details>

  <details>
    <summary>What is JavaScript?</summary>
    <p>JavaScript adds interactivity.</p>
  </details>
</section>

Why this works:

  • Clean layout
  • No JavaScript required
  • Easy to use

Example 2: Open by Default

<details open>
  <summary>Important Note</summary>
  <p>This content is visible by default.</p>
</details>

Explanation:

  • open attribute keeps content expanded

details vs div

Learn more: /html-tags-guide

Feature<details><div>
MeaningSemanticNon-semantic
InteractivityBuilt-inRequires JS
SEOBetterNeutral
AccessibilityHighLow

summary Rules

Understanding <summary> is important.

Key Rules:

  • Must be the first child of <details>
  • Acts as a clickable label
  • Can contain text or HTML

Example:

<details>
  <summary><strong>Click here</strong></summary>
  <p>Hidden content</p>
</details>

Best Practices

Follow these tips for effective usage:

1. Use for Collapsible Content

Ideal for FAQs and hidden information.

2. Keep Summary Clear

Use simple, clickable text.

3. Avoid Overuse

Too many dropdowns can overwhelm users.

4. Style with CSS

You can customize appearance:

details {
  margin-bottom: 10px;
}

5. Use for Better UX

Helps reduce clutter on pages.

Common Mistakes

Missing <summary>

Without it, users can’t toggle content easily.

Overloading Content

Too much hidden content reduces usability.

Using for Layout

Use it only for collapsible sections.

SEO Benefits of details & summary

Using these tags improves SEO and UX.

1. Better Content Organization

Structured content improves readability.

2. Improved User Experience

Users interact with content easily.

3. Accessibility Enhancement

Screen readers can handle these elements well.

4. Reduced Bounce Rate

Interactive content keeps users engaged.

FAQs Section

1. What is the details tag in HTML?

The <details> tag creates collapsible content.

2. What does <summary> do?

It defines the clickable heading for <details>.

3. Can I open <details> by default?

Yes, using the open attribute.

4. Do I need JavaScript for <details>?

No, it works without JavaScript.

5. Is <details> good for SEO?

Yes, it improves structure and user experience.

Scroll to Top