Hacker News new | ask | show | jobs
by pverheggen 226 days ago
Usually you would have it appear when it's focused, like this for example:

https://www.nytimes.com/

And yes, this is an acceptable solution according to the W3C:

https://www.w3.org/WAI/WCAG21/Techniques/general/G1

Your solution of focusing the first form element is pretty idiosyncratic. It's better to follow WAI patterns, because patterns have predictable behavior. Otherwise, keyboard users will have to learn how to interact with your website from scratch, instead of just following the same pattern they're used to from other sites.

1 comments

Any website implementing a form for data entry is expected by any sane user to autofocus the first form element.
I would be very surprised if a website autofocused almost anything on page load, except for very specific applications where that makes sense. I just tried clicking through some forms on gov.uk, which is a website that has spent a _lot_ of time testing and improving the UX of their forms, and none of them had autofocused elements, not even on later pages after having already filled in elements.

I can imagine screen readers would deal particularly poorly with this behaviour, because the user would be dropped in a field without any of the context of the page, just the field label to work with. However, I've not been able to test that out properly.

I don't think the behaviour you're describing is anywhere near as common as you think it is, and I suspect it would make a page less accessible for a number of kinds of users.

Sorry, missed the part about "form for data entry". If that's the main point of the given page, then sure, focus on the first input is fine.

Your original comment was to use tabindex to skip search, menu bars, breadcrumbs, etc. and for that there are better options.