-
Notifications
You must be signed in to change notification settings - Fork 711
[selectors] Should :active
match spacebar down?
#7332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This seems somewhat complement for older issue #4787. Recently, while giving a warning about "this particular CSS trick is not keyboard-accessible, so use it only as the last resort" for a hundredth time (0), I realised that actually I have no idea why things are exactly like this, and that maybe specifying something like
would not make the web explode. What do you think? I see no backward compatibility dangers in this at this point, only that for keyboard and assistive technology users some stuff that already works for mouse users would start working for the first time in the history, what sounds like a pretty nice thing to me. To demonstrate how sad current inconsistent state is (and how hard it is to explain it to a novice), I made a small "game": css-active-keyboard-activation-edge-2025-05-04.223404.mp4Video description"Press to find out…" above list of rectangles of slightly varying sizes, each with a text "Who am I?" inside followed with a blank space. There is also an On-Screen keyboard on the side. At first, mouse pointers gradually points on each item pressing it, what makes it change a colour and reveal text in the blank area. These revealed fragments read "I am a…" and the type of the element: button, link, span, SVG and MATHML. Then the on-screen keyboard is used, pressing the Space Bar button/key for the activation and changing to a next item with the Tab button/ley. Only the "button" element reveals its hidden text this way.This recording is from current MS Edge, which, unlike Firefox (2), at least does (0) Was probably at SO under https://stackoverflow.com/q/79578932/540955 |
Turns out, yes, the HTML spec there says that
And there is even a direct example under
From these two rules it really seems to me that pressing a space bar on a focused Overlooked that in a Roman's comment, what led BZ to (IIUC) ask about which concrete keys should be involved in this process: whatwg/html/issues/2725 |
From the Selectors Level 4 specification
The
:active
pseudo-class is useful for providing immediate feedback about the expected click behavior of an element.Its usage is well documented, in sources from Adobe, Google, Salesforce, Tailwind, and CSS Tricks.
The
:active
pseudo-class is versatile for pointers, in that it is not limited to specific elements.Example from MDN:
There is a keyboard limitation to the
:active
pseudo-class that many sources do not mention. Between the time a user presses the spacebar and releases it, the:active
pseudo-class is only ever applied to a<button>
element. Some resources may even suggest that the pointer-triggered:active
and the keyboard-triggered:active
should always work the same.It is my belief that
:active
state is equally valuable to style for both keyboard and the pointer interactions.Should the
:active
pseudo-class apply to any active element between the times the user presses the spacebar and releases it?I think opening this behavior up to all elements should be considered, or perhaps alongside some other mechanism like
:focusable
.I do not know for certain why
:active
does not behave this way already, but I suspect it is related to the early WWW distinctions between hyperlinks and buttons, similar to how a spacebar press-and-release does not “click” a hyperlink. This is a problematic guess, tho, since the:active
state applies to non-clickable elements when used with a pointer.I was confused by a note in the specification that reads “there may be document-language or implementation-specific limits on which elements can become
:active
.” This note links to the HTML5 specification which defines a list of activatable elements. However, the HTML5 specification does not list any special criteria for spacebar interaction, and the criteria for:active
— which includes “if the element is focusable” — suggests to me that it could apply to any element activated.The text was updated successfully, but these errors were encountered: