<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:
actionis a string — behaves like a native HTMLGETform. 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.actionis 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 callingevent.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">— whenactionis a string, submits the filename rather than the file object (matching native browser behavior).formAction— works in<button>or<input type="submit">to overrideaction, but does not support prefetching.
Examples
Search form
Create a search form that navigates to a results page:app/page.js
searchParams:
app/search/page.js
app/search/loading.js
useFormStatus:
app/ui/search-button.js
Mutations with Server Actions
Pass a Server Action as theaction prop to perform mutations:
app/posts/create/page.js
app/posts/actions.js
