Docs
SEO
Metadata
Viewport Settings

Viewport Configuration

Overview

The configuration for the viewport meta tag is essential for ensuring your web application's layout adapts correctly across various devices and screen sizes. Here, we outline how to customize your viewport settings.

Key Points

  1. Default Behavior

    • The viewport meta tag is set automatically, eliminating the need for manual configuration. The default settings are generally sufficient.
  2. Exporting the Viewport Object

    • The viewport object is exported in the root layout located at /app/layout.js:
      export const viewport = getViewportConfig();
  3. Utility Function for Viewport Configuration

    • getViewportConfig is a utility function defined in a utility file located at /utils/seo.js. This setup allows you to manage and update the viewport configuration easily:
      export const getViewportConfig = () => {
          return {
              width: "device-width",
              initialScale: 1,
              themeColor: settings.COLORS.backgroundColor || "#fff"
          };
      }
  4. Editing the Theme Color

    • To customize the themeColor, navigate to the settings.js file located at the root of the project (/settings.js). Adjust the COLORS.backgroundColor property as needed.
    • Setting the themeColor is beneficial for defining the color of the browser's UI elements, such as the address bar and splash screen on mobile devices. Note that this feature is not supported by all browsers. The default color is set to #fff (white).

Configuration Details

  • File Paths:

    • Utility function: /utils/seo.js
    • Settings file: /settings.js
  • Code Snippets:

    // Root Layout
    export const viewport = getViewportConfig();
    // Utility Function in /utils/seo.js
    export const getViewportConfig = () => {
        return {
            width: "device-width",
            initialScale: 1,
            themeColor: settings.COLORS.backgroundColor || "#fff"
        };
    };
    // settings.js in the project root
    const COLORS = {
    backgroundColor: "#fff"
    };

By following this guide, you can effectively customize the viewport settings for your web application, ensuring a responsive and visually appealing experience across different devices.