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

You Might Not Need WebSockets: The Power of Server-Sent Events
Explore the simplicity and efficiency of Server-Sent Events (SSE) as an alternative to WebSockets for real-time web applications.
Oct 26, 2025

An Introduction to JavaScript Expressions for Developers
Dive into JavaScript expressions with this comprehensive guide. Learn their types, evaluation, and practical applications to boost your coding skills.
Oct 26, 2025

🌊 Week 2 — Pure Cascade Analyzes Your CSS Like Never Before
Pure Cascade has evolved from a UI mockup to a powerful CSS analysis tool, offering metrics and real-time insights for developers.
Oct 25, 2025
