Search forms
Collect a search term and navigate to a results route with the term in the URL.
Next.js 16+ · Component
Next.js's Form component enhances HTML forms with prefetching, client-side navigation, and progressive enhancement. A string action navigates with GET-style URL search parameters; a function action invokes server-side form logic.
Import Form from next/form and give it a destination string. Its controls are submitted as GET parameters, while Next.js enhances the native form with prefetching, client-side navigation, and a JavaScript-free fallback.
<Form action="/path">...</Form>| Name | Type | Description |
|---|---|---|
action | string | function | Destination URL or path, or a function that receives submitted FormData. |
scroll | boolean | Whether to scroll to the top after navigation. |
A React component that renders an enhanced HTML form.
import Form from 'next/form'
export default function SearchForm() {
return (
<Form action="/search">
<input name="query" />
<button type="submit">Search</button>
</Form>
)
}This form submits the query as a URL search parameter and navigates to the search route.
Collect a search term and navigate to a results route with the term in the URL.
Keep the current route while updating filters represented by query parameters.
Submit a form to a Server Action that receives FormData and performs server-side work.
Form is an enhanced HTML form imported from next/form. With a string action, it uses GET semantics, encodes controls into URL search parameters, and performs client-side navigation.
Follow-up: What happens when action is a function? The function receives the submitted FormData, so the form invokes a Server Action rather than navigating to a URL.
When the form enters the viewport, Next.js can prefetch the target route's shared UI, including loading UI. Submission then navigates immediately and can display that loading state while the result loads.
Follow-up: Why is this useful for search? A search form commonly navigates to a results route, so prefetching reduces the apparent transition delay.
String actions preserve the browser's normal form behavior while adding client-side navigation. If JavaScript has not loaded, the submission still works through a full-page navigation.
Follow-up: What should be used for a mutation? Use a function action backed by a Server Action when the form should invoke server-side logic instead of changing the URL.
loading UIclient-side navigationprogressive enhancementServer Actionssearch params