What technique enables a CSS-only modal dialog to be accessible?

Prepare for CSS Mastery with our comprehensive SAD Maintenance and CSA Stand Ups quiz. Enhance your skills with detailed questions, complete with explanations and flashcards. Get ready to excel in your exam!

Multiple Choice

What technique enables a CSS-only modal dialog to be accessible?

Explanation:
The technique hinges on using a hidden checkbox as a simple, CSS-driven toggle. When the checkbox is checked, CSS selectors reveal the modal and hide the background; when unchecked, the modal is hidden again. This lets you create a CSS-only modal without JavaScript. To make the interaction accessible, the modal is given role="dialog" so assistive technologies understand it as a dialog, and it should be labeled with aria-labelledby (or aria-label) to convey its purpose. By marking the background content with aria-hidden when the modal is open, you reduce noise for screen readers and help focus stay on the dialog. If possible, you also aim to move focus into the modal when it opens and to trap focus there, so keyboard users can navigate inside the dialog and close it with a clear control. While not every accessibility detail can be perfectly handled with CSS alone, this combination gives screen readers meaningful signals and keyboard operability in a CSS-only solution. Other approaches fall short on accessibility or practicality. Using display: none and showing via hover either hides content from screen readers or relies on hover, which excludes keyboard and assistive technologies. Relying on JavaScript defeats the CSS-only goal and complicates maintenance of focus and ARIA states. Simply positioning elements without proper ARIA roles leaves assistive technologies without a clear understanding that a dialog is present.

The technique hinges on using a hidden checkbox as a simple, CSS-driven toggle. When the checkbox is checked, CSS selectors reveal the modal and hide the background; when unchecked, the modal is hidden again. This lets you create a CSS-only modal without JavaScript. To make the interaction accessible, the modal is given role="dialog" so assistive technologies understand it as a dialog, and it should be labeled with aria-labelledby (or aria-label) to convey its purpose. By marking the background content with aria-hidden when the modal is open, you reduce noise for screen readers and help focus stay on the dialog. If possible, you also aim to move focus into the modal when it opens and to trap focus there, so keyboard users can navigate inside the dialog and close it with a clear control. While not every accessibility detail can be perfectly handled with CSS alone, this combination gives screen readers meaningful signals and keyboard operability in a CSS-only solution.

Other approaches fall short on accessibility or practicality. Using display: none and showing via hover either hides content from screen readers or relies on hover, which excludes keyboard and assistive technologies. Relying on JavaScript defeats the CSS-only goal and complicates maintenance of focus and ARIA states. Simply positioning elements without proper ARIA roles leaves assistive technologies without a clear understanding that a dialog is present.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy