Search and filtering
A search page needs to place the user's query in the URL while retaining App Router UI state.
Next.js 16+ · Module
Next.js’s <Form> component enhances HTML forms with progressive enhancement, prefetching, and client-side navigation. String actions use GET-style search parameters; function actions invoke a Server Action.
next/form provides a Next.js <Form> component for App Router forms. With a string action, it serializes named controls as URL search parameters and navigates client-side; it can also invoke a Server Action when action is a function.
<Form action={string | function}>...</Form>| Name | Type | Description |
|---|---|---|
action | string | function | URL or path to navigate to, or a Server Action to invoke when submitted. |
formAction | string | function | Submit-control override for a button or submit input. |
A React Form component rendered as an enhanced HTML form.
import Form from 'next/form'
export default function SearchPage() {
return (
<Form action="/search">
<input name="query" placeholder="Search" />
<button type="submit">Submit</button>
</Form>
)
}Submitting navigates to /search?query=... with Next.js client-side navigation.
A search page needs to place the user's query in the URL while retaining App Router UI state.
A form should navigate to a known route without implementing manual submit and router code.
Several submit controls need to target different destinations from one form.
next/form behave when action is a string?With a string action, the component behaves like a native GET form: field values become URL search parameters, then Next.js performs client-side navigation instead of a full reload. This preserves shared UI and client-side state.
Follow-up: What happens when the action is a Server Action? The function is invoked on submission, while client-side navigation still occurs; this approach does not support prefetching.
action prop control?The action string identifies the destination path. An empty string keeps the current route and updates its search parameters, while named form controls supply the encoded query values.
Follow-up: How would you submit to a different destination from one button? Use a button's formAction prop to override the form's action.
Form instead of a native HTML form?The component extends the HTML <form> element with progressive enhancement, prefetching for string destinations, and client-side navigation. It is especially useful when a form updates URL search parameters.
Follow-up: What is a key limitation of manually preventing submission? Calling preventDefault() overrides built-in behavior such as navigation to the specified URL.
client-side navigationprefetchingloading UIServer Actionsearch paramsformAction