Live Examples
HTML Structure
<button class="trigger" id="accountTrigger">
<div class="avatar">JD</div>
<span>John Doe</span>
</button>
<div class="account" id="accountMenu" role="menu">
<div >
<div >JD</div>
<div class="info">
<h3>John Doe</h3>
<p>john@example.com</p>
</div>
</div>
<ul class="menu">
<li class="">
<button class="" role="menuitem">
My Profile
</button>
</li>
</ul>
</div>
Features
- User Avatar - Visual identification with initials
- Account Header - Shows user info and avatar
- Menu Items - Organized action items with icons
- Dividers - Separate menu sections
- Danger Zone - Destructive actions (sign out)
- Smooth Animation - Slide-down menu appearance
Use Cases
- Header Navigation - Top-right user menu
- Profile Access - Quick access to user profile
- Settings - Application preferences
- Account Management - Billing, security, notifications
- Help & Support - Documentation and support links
- Authentication - Sign out and session management
Accessibility
- Use
role="menu"on the dropdown container - Use
role="menuitem"on menu items - Support keyboard navigation (arrow keys, Enter)
- Close menu on Escape key
- Manage focus when opening/closing
- Include aria-labels for icon-only buttons
Responsive Behavior
This component automatically adapts to different screen sizes:
Mobile (< 768px)
On mobile devices:
- Optimized for small screens
- Touch-friendly spacing maintained (44px minimum)
- Text wraps naturally without overflow
- Content density optimized for readability
Desktop (1024px+)
On desktop displays:
- Enhanced visual features
- Hover states and transitions
- Full keyboard navigation support
- Optimal spacing and sizing
Framework Integration
Responsive behavior is automatic:- Framework handles media queries
- No custom CSS required
- Mobile-first approach applied
- Accessibility maintained at all sizes
Best Practices
- Clear Organization - Group related items logically
- User Info Display - Show current user at top
- Icon + Text - Use both for clarity
- Dividers - Separate primary and secondary actions
- Danger Zone - Separate destructive actions at bottom
- Click Outside - Close menu when clicking elsewhere