menu
Semantic container for toolbar buttons and context menu patterns. Provides structure for groups of interactive commands.
Description
The <menu> element represents a group of commands or options. While its original purpose was for context menus, it's now primarily used as a semantic container for toolbar buttons and action menus.
In Vanilla Breeze, <menu> is styled as a flexible container with variants for different menu patterns: toolbars, context menus, vertical menus, and icon button groups.
HTML Semantics
The <menu> element is semantically equivalent to <ul> but signals to assistive technologies that the items represent commands rather than list content. It's the appropriate choice for groups of actions.
When to Use
- Toolbars: Groups of action buttons in editors or applications
- Context menus: Dropdown menus with actions
- Action lists: Vertical lists of commands
- Button groups: Related buttons that function as a unit
- Filter controls: Pill-style toggles for filtering content
When Not to Use
- For navigation links - use
<nav>instead - For content lists - use
<ul>or<ol> - For dropdown selection - use
<select>
Variants
Default Menu
The default menu displays as a horizontal flexbox container.
.toolbar
Horizontal toolbar with background and contained button styling.
.context
Dropdown-style context menu with separators.
.context with Links
Context menus can also contain links for navigation actions.
.vertical
Vertical menu layout for sidebar or dropdown patterns.
.icons
Icon-only toolbar with square icon buttons.
.pills
Pill-shaped buttons for filter or toggle patterns.
.compact
Reduced spacing for dense interfaces.
Styling
CSS Implementation
Variant Classes Summary
| Class | Description |
|---|---|
.toolbar |
Horizontal toolbar with background container |
.context |
Dropdown-style menu with shadow and separators |
.vertical |
Vertical stacking layout |
.icons |
Square icon-only buttons |
.pills |
Pill-shaped button items |
.compact |
Reduced spacing and font size |
Menu Separators
Use role="separator" on list items to create visual dividers in context menus.
Accessibility
Semantic Structure
The menu element conveys that its items are commands. Each <li> should contain a <button> or <a> for proper interaction.
ARIA Roles
role="separator"- Marks visual dividers between groups of itemsaria-label- Use on icon-only buttons to describe the actionaria-disabled- For non-functional menu items
Icon Buttons
When using icon-only buttons, always include an aria-label for screen reader users:
Keyboard Navigation
Menu buttons receive standard keyboard focus. For more complex menu patterns with arrow key navigation, consider using ARIA menu roles or a JavaScript-enhanced component.
| Key | Action |
|---|---|
| Tab | Move focus between menu buttons |
| Enter / Space | Activate focused button |
Combining Variants
Variants can be combined for different effects.
Related Elements
Browser Support
The <menu> element is supported in all browsers. Its semantic meaning is recognized by screen readers, though the element renders identically to <ul> by default.