Looking to be accepted

We all seem to be looking for acceptance in one way or another. We look for acceptance (love, approval) from friends, business associates, family, and sometimes even strangers. We look at social…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Set Input Focus with HTML5 autofocus

Use the autofocus attribute on form elements to automatically focus the input field when the page loads 👍

This is super handy if your site has a form and you can automatically select the first input field and your user can start typing right away 👏

For example, if you have a search site like google, you can use this attribute to automatically select the search field. That way your user can start typing immediately without needing to click on the input field first. Yay, awesome User Experience 🤩

You can apply the autofocus attribute on:

Note you can’t apply autofocus on inputs of type hidden because hidden inputs can't be focused.

Also, autofocus can only be on one element on one page. So don't use it on multiple elements.

I’ll be remiss not to mention some of the accessibility concerns of autofocus. So please keep this in mind before using this attribute.

I also want to point a possible solution of using aria-describedby that may help with this. Of course, if you know of any other solutions, please do share!

When this alert loads, the autofocus is kicked in to automatically select the "Do not delete" button. However, due to the limitation of autofocus for screen readers. This is not ideal for accessibility. A possible solution is to utilize the aria-describedby attribute. So the screen reader will now announce: "Are you sure? dialog. Once you delete this thing, it’s gone forever! Do not delete, button."

Add a comment

Related posts:

QR vs NFC

Optimized for different use-cases, NFC tags and QR-Codes each have their strengths and weaknesses. Here we break down each technology, what it does well, what it lacks, and where each works best…

20 min SEO Checklist You Need to Check Today!

website seo check list

Running with Scissors

As soon as it grew dark, I took off in our neighborhood, running with scissors. My quest was to bring home the prettiest bouquet for my mother. I was 10. With scissors in one hand, I ran to and fro…