Type a static viewport export
A route has fixed responsive display settings.
Next.js 16+ · Type Alias
Viewport is the TypeScript type for Next.js App Router viewport configuration. Use it to type a static viewport export or the result of generateViewport.
Viewport is the type for the object exported as viewport or returned by generateViewport. It describes initial display settings such as width, scale, color scheme, and theme color; Next.js turns the configured values into viewport-related HTML metadata.
type Viewport = { width?: string | number; initialScale?: number; minimumScale?: number; maximumScale?: number; userScalable?: boolean; viewportFit?: string; themeColor?: string | ThemeColorDescriptor | Array<ThemeColorDescriptor>; colorScheme?: ColorScheme }A Viewport object containing one or more viewport fields when used as the return type of generateViewport.
viewport export or a dynamic generateViewport export per route segment.import type { Viewport } from 'next'
export const viewport: Viewport = {
width: 'device-width',
initialScale: 1,
themeColor: '#ffffff',
}
export default function Page() {
return <main>Responsive page</main>
}Export a typed viewport object from a route page or layout.
A route has fixed responsive display settings.
Viewport settings depend on route or application data.
A shared layout defines consistent viewport behavior.
Viewport type?Viewport describes the shape of viewport configuration used by Next.js. A route can export a statically typed viewport object, or generateViewport can return a Viewport object dynamically.
Follow-up: Why should it not be exported from a Client Component? Metadata exports are resolved on the server before the page renders, so viewport configuration belongs in Server Components.
viewport instead of generateViewport?Use a static viewport export when the values are known ahead of time. Use generateViewport when the returned viewport values depend on data available while rendering the route.
Follow-up: What constraint applies when both forms appear in one route segment? They cannot both be exported there; select one configuration mechanism.
Viewport represent?The type supports settings that control the page's initial viewport presentation, including width, initial scale, color scheme, and theme color. Next.js uses the object to produce viewport-related metadata.
Follow-up: Why should dynamic viewport logic avoid request-bound or uncached data with Cache Components? Viewport metadata affects the initial page load and cannot be deferred behind a Suspense boundary.
generateViewportviewportViewport fieldsServer Components