Navigation Dropdown
Demo
@import url('https://fonts.googleapis.com/css2?family=Barlow&family=Oswald&display=swap');
body {
font-family: 'Barlow', sans-serif;
background-color: #fff;
color: #005E86;
}
.navigation {
width: 75%;
margin: auto;
font-size: 1.2em;
}
.nav-list {
list-style: none;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
}
.nav-list a {
text-decoration: none;
color: #005E86;
border-bottom: 3px solid transparent;
transition: border-color 0.3s ease-in-out;
}
.nav-list a:hover,
.nav-list a:focus {
border-color: #211224;
}
.has-submenu {
position: relative;
}
.submenu {
display: none;
position: absolute;
top: 100%;
left: 0;
background-color: #fff;
border: 1px solid #99b4c0;
padding: 10px;
width: 120px;
font-size: .9em;
}
.submenu li {
list-style: none;
margin-bottom: 5px;
}
.submenu a {
color: #211224;
text-decoration: none;
}
/* Show submenus when the 'visible' class is added */
.submenu.visible {
display: block;
}
.current {
border-bottom: 3px solid #211224;
}
Why use dropdown menus?
Navigation menus with dropdowns are employed in web development to organize and present site content in a structured and accessible manner. These menus enhance user experience by categorizing information hierarchically, allowing visitors to navigate through a website’s sections or pages efficiently. Dropdown menus provide a compact way to display extensive navigation options without cluttering the interface, promoting a clean and organized design. From an accessibility standpoint, well-designed dropdown menus can improve site accessibility by enabling keyboard navigation, ensuring proper focus management, and offering clear labels and instructions that assist screen reader users. When implemented with accessibility in mind, these menus contribute to a more inclusive browsing experience, accommodating users of various abilities and interaction preferences.
What are some accessibility concerns?
- Keyboard Accessibility:
- Concern: Dropdown menus might be inaccessible or challenging to navigate using a keyboard.
- Mitigation: Ensure the dropdown menus are keyboard accessible by enabling navigation using the Tab key and ensuring proper focus management. Use ARIA roles and attributes (role=”menu”, role=”menuitem”, etc.) to convey the menu’s structure and allow users to navigate through dropdown options with arrow keys and Enter/Space for selection.
- Screen Reader Compatibility:
- Concern: Screen reader users might have difficulty understanding or accessing the dropdown content.
- Mitigation: Utilize proper ARIA roles and labels to convey the dropdown’s purpose and relationships between menu items. Ensure that screen readers announce the dropdown’s visibility, state changes, and associated actions accurately.
- Visibility and Consistency:
- Concern: Dropdown menus might not be visually noticeable or consistent across different devices or screen sizes.
- Mitigation: Ensure dropdown menus are visually distinct and clearly visible, especially for users with low vision. Implement responsive design principles to adapt the dropdown layout for different screen sizes while maintaining consistency and usability.
- Focus Management and Interaction:
- Concern: Users might lose context or encounter issues when navigating through dropdowns.
- Mitigation: Implement clear and consistent focus styles to indicate the focused item within the dropdown. Use appropriate keyboard interactions to manage dropdown visibility, ensuring users can easily access and navigate within the dropdown without abrupt changes or loss of context.
- Touch and Mobile Usability:
- Concern: Dropdown menus might be challenging to interact with on touch devices or smaller screens.
- Mitigation: Optimize dropdown interaction for touch devices by providing larger tap areas and considering touch gestures. Ensure dropdowns expand and collapse smoothly without covering crucial content on smaller screens.
- Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text.
- All functionality of the content is operable through a keyboard interface without requiring specific timings for individual keystrokes, except where the underlying function requires input that depends on the path of the user's movement and not just the endpoints.
- If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability.
- For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies.