splitforms.com

HTML · ATTRIBUTE

HTML autofocus Attribute: Focus an Input on Page Load

Last reviewed

autofocus is a boolean global attribute that asks the browser to focus an element when the page loads, or when a dialog containing it opens with showModal(). Use it on only one element per page. Content added later does not normally receive autofocus unless it is in a dialog being opened. iOS Safari and some Android browsers usually will not open the on-screen keyboard without a user tap. The attribute is never submitted with form data.

  • Live, editable example
  • Copy-paste snippet
  • Attributes & common mistakes
Live demo · nothing is sent

What gets submitted

Fill in the form above and press its button. The demo stops the request and lists every name=value pair the browser would send, plus the controls it leaves out.

With a free access key in the form, these fields land in your splitforms dashboard; access_key and botcheck are read by splitforms, not stored as lead data.

Edit the HTML and re-run it
Runs in a sandbox. Nothing is sent.

Minimal snippet

autofocus-example.html
<input type="search" name="q" autofocus>

Copy-paste code

HTML autofocus Attribute code you can paste today.

Replace YOUR_ACCESS_KEY with a key from your free splitforms dashboard. The form posts to one endpoint — submissions land in your inbox and dashboard with spam filtering built in.

Get free access key
autofocus.html
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">

  <label for="name">Name</label>
  <input type="text" id="name" name="name" autofocus required>

  <label for="message">Message</label>
  <textarea id="message" name="message" rows="4" required></textarea>

  <!-- Honeypot: hidden from people, bots fill it in -->
  <input type="checkbox" name="botcheck" style="display:none" tabindex="-1" autocomplete="off">

  <button type="submit">Send</button>
</form>

Attributes · autofocus

Which attributes affect autofocus?

Focus requires an eligible, visible element; these attributes affect focus behavior.

HTML autofocus Attribute attributes and what each one does
AttributeWhat it doesDocs
autofocusA boolean global attribute that requests focus when the page loads or its containing dialog opens.MDN
disabledA disabled form control cannot receive focus. Enable it before requesting focus.MDN
tabindexControls whether an element can receive focus and how it participates in keyboard navigation.MDN

Common mistakes

autofocus mistakes to avoid

Choose focus deliberately and account for browser and accessibility behavior.

  1. Use autofocus where it helps the task

    A search page, login, single-purpose form, or the first field in a dialog can benefit from immediate focus. Use only one autofocus element per page; if several compete, the browser focuses the first eligible candidate.

  2. Avoid surprising visitors on long pages

    Automatic focus can scroll past introductory content. Screen-reader users may land in a field without hearing the content before it, and a mobile keyboard can obscure the page. Keep a visible label and let visitors choose where to start when context matters.

  3. Why autofocus is not working

    Multiple autofocus elements compete; an element added after page load by JavaScript or a framework does not normally autofocus unless it is in a dialog being opened. A field hidden with display:none or disabled cannot be focused. Focus inside an iframe may also depend on browser and embedding restrictions. When appropriate, make the field visible and enabled, then call el.focus({ preventScroll: true }); after it is inserted. This does not bypass browser restrictions.

  4. Mobile browsers control the keyboard

    iOS Safari and some Android browsers usually require a user tap before opening the on-screen keyboard. Focusing a field programmatically does not guarantee the keyboard will appear; allow the visitor to tap the field.

  5. Use autoFocus in React

    React uses the camelCase autoFocus prop and applies focus itself when the element mounts: <input name="q" autoFocus />. Browser focus and mobile keyboard restrictions still apply.

Sources: WHATWG HTML Standard: autofocus · MDN: autofocus

Copy-paste ready

The HTML autofocus Attribute example below is a complete, working form — paste it into any HTML page and it submits, no edits to the markup required.

No backend to build

Your html autofocus attribute form posts to one endpoint. No server, PHP, or API route — accepted submissions are saved to your dashboard before owner notification email is attempted; delivery time and inbox placement depend on provider and recipient settings.

A form that really submits

Unlike a static reference snippet, this autofocus form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML autofocus Attribute to any page.

Copy the html autofocus attribute example, drop in your free access key, and paste it into any page — submissions start landing in your dashboard.

Copy the code

Copy the HTML autofocus Attribute example below.

Add your access key

Replace YOUR_ACCESS_KEY with a free splitforms key from the dashboard.

Paste into your site

Drop the form into any HTML page. Submissions arrive in your dashboard.

How SplitForms works

What happens after someone submits your form?

splitforms receives the submission, filters spam, saves it to your dashboard and emails you — then, on paid plans, sends it on to your webhooks and integrations. No backend infrastructure to build.

A SplitForms contact form submission launching straight to your inbox

Add your endpoint

Point your form to your unique SplitForms endpoint. That's it.

HTML form pointing at a SplitForms submit endpoint

Receive submissions

We instantly capture and organize every submission in your inbox.

Submissions inbox with searchable leads and status pills

Route anywhere

Send data to email, spreadsheets, CRMs, webhooks, and 7,000+ apps.

Generic integration tiles for email, sheets, chat, CRM, automate, and webhook

No credit card required. Set up in under 60 seconds.

Connect & automate

Where can submissions go besides email?

On paid plans, submissions can also go to Slack, Discord, Google Sheets, Notion, Airtable, Zapier or any signed webhook — and splitforms works on the platforms you build on, from WordPress and Shopify to Next.js. With Stripe connected, your forms can take payments too.

Connect your SplitForms form to Slack, Google Sheets, Mailchimp, Zapier and more
NewTake payments on your formsDeposits, bookings, order forms — submitters check out through Stripe and the money goes straight to your Stripe account. Included on every paid plan.See payment forms →Need time slots? Online booking →

Setup guides for the stacks you use

Questions

HTML autofocus Attribute questions, answered.

View all FAQs
How do I autofocus an input in HTML?

Add the boolean autofocus attribute to the input, such as <input type="search" name="q" autofocus>. Use it on only one element per page and provide a label.

Does autofocus work in a modal dialog?

Yes. An autofocus element inside a dialog can receive focus when the dialog opens with showModal(). Choose the most appropriate initial focus for the dialog, which is not always its first input.

Why does autofocus not open the mobile keyboard?

Mobile browsers can require a user gesture before showing the keyboard. A visitor can tap the field to open it, even if the browser has already focused it.

How do I autofocus an input in React?

Use the camelCase autoFocus prop, for example <input autoFocus />. React applies focus when the element mounts, subject to browser restrictions.

Is autofocus submitted with the form?

No. autofocus controls focus behavior; it is not submitted as form data.

Simple pricing

How much does splitforms cost?

Free gives you 500 submissions for $0 — no card, no time limit. Pro is $5/month for 5,000 submissions a month, and Annual is $49/year for 15,000 a month with every Pro feature.

Free

$0— 500 submissions
 

No card, no time limit

Best for testing

For side projects and indie devs.

  • 500 free submissions
  • Unlimited forms
  • Email notifications included
  • Smart spam filtering
  • Submissions dashboard
  • Redirect after submit
  • MCP server included

Annual

$49/ year
About $4.08 per month, billed yearly
Best value

Every Pro feature with triple the volume — $0.27 per 1,000 at full use.

  • 15,000 submissions per month
  • Unlimited forms
  • Everything in Pro
  • File uploads with 5 GB storage
  • 3 team seats
  • Priority email support

No credit card required on Free • Cancel anytime • Full pricing and FAQ