Modern CSS & Accessibility

Showcasing Best Practices

This page demonstrates accessible components using modern CSS, combining aesthetic design with inclusive principles.

Try this: Use the 'Tab' key to navigate. The "Skip to main content" link should appear first. The navigation links and theme toggle are focusable. Pressing 'Enter' on the skip link jumps you past the header.

Accessible Form Validation

This form uses :user-valid and :user-invalid CSS pseudo-classes for feedback, avoiding distracting error messages before user interaction. Error messages use aria-live.

Please enter your name. Looks good!
Please enter a valid email address (e.g., user@example.com). Valid email!
You must agree to the terms. Agreed!

Semantic HTML & Landmarks

Using HTML elements for their intended purpose gives inherent meaning and structure, crucial for assistive technologies and overall robustness.

<header> (Page/Site Banner)
<main> (Primary Page Content)
<article> (Self-contained piece)

Article Title

Article content goes here...

<section> (Themed group)

Section content...

<footer> (Page/Site Footer)

Accessible Images & Graphics

Visuals need text alternatives (alt text) so their content or function is accessible to users who cannot see them.

Image Examples:

Informative Graphic (CSS Gradient):

aria-label provides the text alternative for this CSS background image.

Decorative Graphic (CSS Gradient):

Empty aria-label="" marks this purely decorative graphic to be ignored by screen readers. Alternatively, assign role="presentation".

Image in a Figure:

Figure 1: The device features a complex pattern.

<figure> groups the graphic and its <figcaption>. aria-label still describes the graphic itself.

Icon Font (Font Awesome):

Settings Button Text

Icon font is hidden (`aria-hidden`). Accessible text provided via adjacent text or visually hidden span.

Inline SVG Icon:

Information Icon More Information

Inline SVG uses <title> (referenced by aria-labelledby) for its accessible name. `role="img"` clarifies its purpose. `focusable="false"` prevents redundant tab stops.

Color Contrast & Cues

Sufficient contrast between text/UI elements and their background is crucial. Color should not be the only means of conveying information.

Good Contrast Examples (AA):

Regular Text (4.5:1+)

Large Text (3:1+)

Bad Contrast Examples:

Low Contrast

Low Contrast

Non-Color Cues:

This link uses an underline on hover/focus in addition to color difference.

Error: Using icon and bold text, not just red color.

Success: Using icon and bold text, not just green color.

Purposeful ARIA: Live Regions

ARIA (Accessible Rich Internet Applications) adds semantics where HTML lacks them, especially for dynamic content. Use native HTML first! ARIA live regions allow screen readers to announce changes without the user having to shift focus.

System Status:

Idle. Click button to simulate updates.

Accessible Data Table

Proper table markup (<caption>, <thead>, <th> with scope attributes) is essential for screen readers to interpret data relationships correctly.

Browser Feature Support Matrix - April 2025
Feature Chrome Firefox Safari Edge
CSS Nesting Yes Yes Yes Yes
:has() Selector Yes Yes Yes Yes
Container Queries Yes Yes Yes Yes
View Transitions API Partial No No Partial
Overall Support Varies by feature and browser version.

Respecting Motion Preferences

Animations can cause issues for users with vestibular disorders, epilepsy, or cognitive impairments. Use the prefers-reduced-motion media query and provide controls where appropriate.

Example Animation:

Spinning Box

Control (Simulation):

This toggle simulates the OS setting for demo purposes. Check your OS Accessibility settings to test prefers-reduced-motion directly.

Warning: By default, toggles don't support Enter as the activiation key. Use spacebar. Enter is reserved for form submission.

Accessible Custom Disclosure (Accordion)

While native <details>/<summary> is often best, sometimes a custom accordion is needed. This requires careful use of ARIA attributes and JavaScript for keyboard interaction.

Frequently Asked Questions

Focus Management Concepts

Managing keyboard focus programmatically is crucial for accessible dynamic interfaces like modals, menus, and single-page applications.

Focus Management Example:

Example Scenario: Modal Dialog

(A real modal implementation requires significant JavaScript for focus trapping, state management, and ARIA attributes.)