Overview
Collapsible sections allow users to collapse and expand page sections by clicking on section headings. This feature helps navigate long articles by hiding content that isn’t immediately relevant, improving readability and reducing scrolling.Collapsible sections are enabled per-page based on configuration. The feature requires the
citizen-sections-enabled CSS class on the <body> element.How It Works
User Experience
When collapsible sections are enabled:- Section headings become interactive - Clicking a heading toggles the section’s visibility
- Visual indicators - Section headings show clickable styling
- Smooth transitions - Sections expand and collapse with animation
- Preserved edit links - Edit section links remain functional and don’t trigger collapse
Interaction
- Click heading - Toggle the section open/closed
- Click edit link - Edit section (doesn’t trigger collapse)
- Sections collapse to
hidden="until-found"- Browser can still find text in collapsed sections
Enabling Collapsible Sections
Collapsible sections are controlled by the presence of thecitizen-sections-enabled class on the body:
HTML Structure
Collapsible sections use a specific HTML structure:Required Classes
citizen-section-heading- Applied to heading elements (h2, h3, etc.)citizen-section- Applied to the collapsible content containermw-editsectionormw-editsection-like- Edit links that shouldn’t trigger collapse
Implementation Details
JavaScript Behavior
The collapsible sections feature is implemented insections.js:
Event Handling
- Click event bubbles up to the body content container
- Check if click target is within a heading using
closest('.citizen-section-heading') - Ignore edit section links by checking for
mw-editsectionclasses - Toggle the next sibling element if it has the
citizen-sectionclass - Set
hiddenattribute to eitherfalse(visible) or'until-found'(collapsed)
The
hidden="until-found" value is a modern HTML feature that allows collapsed content to be found by browser search functionality.Styling
Collapsible sections require corresponding CSS to provide visual feedback:Accessibility
The collapsible sections feature includes accessibility considerations:- Semantic HTML - Uses proper heading hierarchy
hidden="until-found"- Modern HTML attribute for collapsible content- Keyboard accessible - Headings are clickable via keyboard
- Edit links preserved - Accessibility of edit functionality maintained
Screen Readers
Consider adding ARIA attributes for better screen reader support:Integration with Table of Contents
Collapsible sections work in conjunction with the Table of Contents feature. When a TOC link is clicked:- Browser navigates to the heading anchor
- If the section is collapsed, the browser automatically expands it (due to
hidden="until-found") - The page scrolls to the heading
- User sees the relevant content
Configuration Options
While collapsible sections don’t have user-facing preferences, administrators can control when they’re enabled:Per-Page Control
Use page properties or templates to add the enabling class:Global Configuration
InLocalSettings.php, you can enable collapsible sections for specific namespaces or conditions:
Best Practices
Avoid using collapsible sections on very short articles - they add complexity without benefit.
Browser Compatibility
Thehidden="until-found" attribute is supported in:
- Chrome/Edge 102+
- Safari 16+
- Firefox (behind flag)
Technical Dependencies
- ResourceLoader module:
skins.citizen.scripts - JavaScript file:
resources/skins.citizen.scripts/sections.js - Dependencies: MediaWiki core, DOM APIs
- Initialization: Automatic on page load
Example Use Case
Documentation Wiki
For a software documentation wiki:- Enable collapsible sections on all documentation pages
- Users can collapse completed sections as they work through tutorials
- Long reference pages become more navigable
- Find-in-page still works for searching specific terms
Encyclopedia
For an encyclopedia-style wiki:- Enable on articles with 5+ sections
- Readers can focus on sections of interest
- Overview sections can remain visible while details are collapsed
- Mobile users benefit from reduced scrolling
Troubleshooting
Sections Don’t Collapse
- Check that
citizen-sections-enabledclass is on<body> - Verify section HTML structure matches required format
- Ensure JavaScript hasn’t been disabled
- Check browser console for errors
Edit Links Trigger Collapse
- Ensure edit links have
mw-editsectionormw-editsection-likeclass - Check that event handler properly filters edit section clicks
Sections Don’t Expand from Search
- Verify
hidden="until-found"attribute is used (not justhidden) - Check browser compatibility for
hidden="until-found"feature