Create a CSS-only accordion using details and summary elements. Animate the height opening using the grid-template-rows 0fr to 1fr transition trick. Make sure Ctrl+F find works so the browser automatically expands the detail if searched text is hidden inside.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
The user wants me to create a CSS-only accordion using the <details> and <summary> HTML elements with smooth height animation. They want:
CSS-only accordion (no JavaScript)
Using <details> and <summary> elements
Animate height opening using the grid-template-rows 0fr to 1fr transition trick
Make sure Ctrl+F find works and automatically expands details if searched text is hidden inside
The grid-template-rows 0fr to 1fr trick is a clever technique where:
0fr means 0 * (remainder space) = 0 height
1fr means 1 * (remainder space) = full available space
This allows smooth height animation without knowing the exact height
The tricky part is the Ctrl+F find functionality. The <details> element has built-in support for this in most browsers - when you search for text inside a closed <details> element, the browser automatically opens it. However, we need to make sure our CSS doesn't break this functionality.
Let me create a solution:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS-Only Accordion with Animation</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
padding: 2rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
max-width: 700px;
margin: 0 auto;
}
h1 {
color: white;
margin-bottom: 2rem;
text-align: center;
}
details {
background: white;
border-radius: 8px;
margin-bottom: 1rem;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
summary {
padding: 1rem;
cursor: pointer;
user-select: none;
font-weight: 600;
color: #333;
background: #f8f9fa;
transition: background-color 0.2s ease;
display: flex;
align-items: center;
gap: 0.5rem;
}
summary:hover {
background: #e9ecef;
}
summary::marker {
color: #667eea;
}
details[open] > summary {
background: #e7f0ff;
color: #667eea;
}
details > :not(summary) {
display: grid;
grid-template-rows: 0fr;
overflow: hidden;
transition: grid-template-rows 0.3s ease;
}
details[open] > :not(summary) {
grid-template-rows: 1fr;
}
.content {
min-height: 0;
padding: 1rem;
color: #666;
line-height: 1.6;
}
</style>
</head>
<body>
<div class="container">
<h1>CSS-Only Accordion</h1>
<details>
<summary>What is this accordion?</summary>
<div class="content">
This is a pure CSS accordion built with HTML5 `<details>` and `<summary>` elements. It uses the grid-template-rows trick for smooth height animation without JavaScript. Try using Ctrl+F to search for text inside closed sections - they'll automatically expand!
</div>
</details>
<details>
<summary>How does the animation work?</summary>
<div class="content">
The animation uses CSS Grid's `grid-template-rows` property with `0fr` and `1fr` values. When closed, it's set to `0fr` (zero height), and when open, it transitions to `1fr` (full available space). This creates a smooth height animation without needing to know the exact content height.
</div>
</details>
<details>
<summary>Does Ctrl+F work?</summary>
<div class="content">
Yes! The browser's native find functionality automatically opens `<details>` elements when the search text is found inside them. This works because we're using semantic HTML and not breaking the default behavior with our CSS.
</div>
</details>
<details>
<summary>Can I customize the styling?</summary>
<div class="content">
Absolutely. You can modify the colors, padding, border-radius, shadows, and transition duration. The key CSS properties to keep are the `grid-template-rows` animation and the `overflow: hidden` on the details element to prevent content from showing during the transition.
</div>
</details>
</div>
</body>
</html>
This solution uses the grid-template-rows technique to smoothly animate the accordion opening and closing. The details[open] selector targets open accordions and transitions from 0fr to 1fr. The browser's native find-in-page functionality automatically expands closed details elements when matching text is found, preserving accessibility and search functionality without any JavaScript. The grid-template-rows approach needs the content wrapped in a grid container. The direct child of details should be a grid that transitions between 0fr and 1fr, with the actual content nested inside it to respect the grid constraint.
The structure requires a container div with display: grid that animates its rows, and a child element with overflow: hidden to enforce the sizing. When the details element opens, the grid expands from taking zero space to taking up the full content space. I need to reconsider the selector approach. Using :not(summary) could work, but it might select multiple elements if there are siblings. Being more explicit with a class on the content wrapper is cleaner.
Let me build out a complete solution with proper HTML structure and CSS. I'll use a dedicated wrapper class for the collapsible content to ensure the grid animation targets only what needs to animate. The details element's open attribute will control the state, and the grid-template-rows transition will smoothly animate between 0fr and 1fr based on whether details is open or closed. I cannot complete this thought. The partial thinking appears to be CSS code that's been cut off mid-property, and the next thinking continues the same CSS styling without providing a logical completion point or new conceptual direction to summarize. I cannot complete this thought. The current rewritten thinking appears to be incomplete CSS code, and the next thinking contains HTML markup and content that doesn't logically continue the styling rules. There's a disconnect between the partial CSS rule for code elements and the subsequent HTML structure, making it difficult to create a coherent continuation. The grid-template-rows transition from 0fr to 1fr animates height changes smoothly regardless of content size. When collapsed, 0fr allocates no space, and when expanded, 1fr takes the full available space. CSS transitions handle the animation between these states, while overflow: hidden prevents content from spilling out during the transition. I cannot complete this thought. The next thinking appears to be HTML content rather than Claude's thinking process, so I'm unable to finish the partial thought or rewrite it meaningfully. I'm verifying the implementation handles all the requirements correctly. The grid-based animation with overflow hidden on the accordion body should work without interfering with search functionality, since the content remains in the DOM and isn't hidden with display properties. The native <details> element automatically opens when matching text is found via Ctrl+F, and since I'm not using JavaScript or problematic CSS hiding techniques, the browser's find feature should work as expected.
Let me finalize the code to ensure everything is properly structured and styled for smooth animations with full accessibility support.
html
I'm completing the accordion structure with the arrow icon sizing and styling, then adding the hover effects and animation logic. The grid-based animation approach transitions smoothly between collapsed and expanded states. I've included the full HTML markup with three accordion items demonstrating the FAQ pattern, styled with a gradient theme and smooth transitions for the expand/collapse interactions. I cannot complete this thought. The original thinking appears to be HTML markup and code rather than Claude's thinking process, so there's no internal reasoning to rewrite or summarize.
CSS-Only Accordion with Grid Animation
Here's a complete solution using <details> and <summary> with smooth grid-template-rows animations: