Skip to main content
The <Form> component extends the HTML <form> element with client-side navigation on submission, prefetching of loading UI, and progressive enhancement. It is particularly useful for search forms that update URL search params.
app/ui/search.js

Behavior

The behavior of <Form> depends on the type of the action prop:
  • action is a string — behaves like a native HTML GET form. Form data is encoded as URL search params and Next.js performs a client-side navigation instead of a full page reload. Shared UI (layouts, loading states) is preserved. The path is also prefetched when the form enters the viewport.
  • action is a function (Server Action) — behaves like a React form, executing the action on submit.

Props

When action is a string

string
required
The URL or path to navigate to on form submission. An empty string "" navigates to the same route with updated search params.
boolean
default:"false"
When true, replaces the current history entry instead of pushing a new one.
boolean
default:"true"
Controls scroll behavior on navigation. When true, scrolls to the top of the new route and maintains scroll position for back/forward navigation.
boolean
default:"true"
Controls whether the destination path is prefetched when the form becomes visible in the viewport.

When action is a function

function
required
A Server Action to call when the form is submitted. See the React docs for details.
When action is a function, the replace and scroll props are ignored.

Caveats

  • onSubmit — can be used to handle submission logic, but calling event.preventDefault() will override <Form> navigation behavior.
  • method, encType, target — not supported as they override <Form> behavior. Use a plain HTML <form> if you need these.
  • <input type="file"> — when action is a string, submits the filename rather than the file object (matching native browser behavior).
  • formAction — works in <button> or <input type="submit"> to override action, but does not support prefetching.

Examples

Search form

Create a search form that navigates to a results page:
app/page.js
On the results page, read the query from searchParams:
app/search/page.js
Show a loading state while results load:
app/search/loading.js
For immediate feedback before the loading UI appears, use useFormStatus:
app/ui/search-button.js

Mutations with Server Actions

Pass a Server Action as the action prop to perform mutations:
app/posts/create/page.js
app/posts/actions.js