Pure CSS Tabs With Details, Grid, and Subgrid
Discover how to build pure CSS tabs using the <details> element, CSS Grid, and Subgrid for an accessible, elegant design.

How to Create Pure CSS Tabs with <details>
Creating a tabbed interface enhances user experience by organizing content in a clean, accessible manner. But did you know you can build this interface using just <details>? This method leverages native HTML elements and CSS for a visually appealing experience. Let's dive into how to create pure CSS tabs using <details>, CSS Grid, and Subgrid.
Why Opt for <details> Element in Tabs?
Choosing the <details> element for your tabs brings multiple advantages:
- Semantic HTML: It boosts accessibility and SEO, making your content more understandable to screen readers.
- Built-in Functionality: The element supports an open/close state naturally, removing the need for JavaScript.
- Ease of Styling: Styling your tabs with CSS becomes straightforward, without the need for complex scripting.
Crafting the Basic Structure
To kick off, you need a straightforward HTML structure. Here's a quick example:
<details>
<summary>Tab 1</summary>
<div class="content">
<p>This is the content for Tab 1.</p>
</div>
</details>
<details>
<summary>Tab 2</summary>
<div class="content">
<p>This is the content for Tab 2.</p>
</div>
</details>
How to Style Tabs Using CSS Grid
With your HTML ready, it's time to style it using CSS Grid. Here's a start:
Basic CSS for Your Tabs
Begin with some basic styles to position your tabs:
details {
display: grid;
grid-template-columns: 1fr;
margin-bottom: 10px;
}
summary {
background-color: #007bff;
color: white;
padding: 10px;
cursor: pointer;
border-radius: 5px;
}
.content {
display: none;
padding: 10px;
border: 1px solid #ccc;
}
details[open] .content {
display: block;
}
This setup uses CSS Grid for layout management, showing or hiding content based on the <details> element's open state.
Implementing Subgrid for Nested Tabs
Subgrid enables child elements to inherit their parent's grid layout, perfect for nested tabs.
Nested Tabs Example
Here's how you can create tabs within tabs:
<details>
<summary>Main Tab 1</summary>
<div class="content">
<details>
<summary>Sub Tab 1A</summary>
<div class="content">
<p>Content for Sub Tab 1A.</p>
</div>
</details>
<details>
<summary>Sub Tab 1B</summary>
<div class="content">
<p>Content for Sub Tab 1B.</p>
</div>
</details>
</div>
</details>
How to Style Nested Tabs
Adjust the CSS like so:
.content {
display: grid;
grid-template-columns: 1fr;
}
.content details {
margin: 5px 0;
}
This approach helps you maintain an organized and visually appealing tabbed interface.
Best Practices for Designing CSS Tabs
When creating CSS tabs, remember:
- Accessibility: Ensure tabs are navigable via keyboard and accessible to screen readers.
- Responsive Design: Employ media queries for mobile-friendly layouts.
- Visual Feedback: Offer cues for active and inactive tabs to improve the user experience.
Conclusion
Using <details>, CSS Grid, and Subgrid for pure CSS tabs boosts efficiency and accessibility, minimizing JavaScript reliance. This method provides a neat, organized interface. Apply these strategies in your projects to enhance content presentation and user engagement.
Embrace modern CSS features to craft intuitive, responsive designs that uplift the user experience. Start exploring these techniques today!
Related Articles

The Most Hated CSS Feature: Exploring cos() and sin()
Explore the often-misunderstood CSS functions cos() and sin(). Learn practical applications that can elevate your web design skills.
Sep 17, 2025

Unlocking CSS Typed Arithmetic: A New Era for Web Design
CSS Typed Arithmetic in Chrome 140 revolutionizes how developers calculate styles, allowing for mixed data types in CSS. Learn how to simplify your coding today.
Sep 26, 2025

Unlocking the Potential of Corner-Shape in CSS
Explore how corner-shape in CSS transforms web design, enhancing aesthetics and user experience with unique shapes.
Sep 20, 2025