How to Create a Custom Layout in Next.JS
Next.js is a powerful framework for building high-performing React applications. One of its features is the ability to create custom layouts for your pages allowing you to create a consistent design that’s easy to maintain and update across your application.
Creating a Custom Layout Component in Next.JS
In the folder namedcomponentsin your Next.js project, createLayout.jsxand add the following code to create the layout component.
This component imports the Header and Footer components andaccepts children as props. It renders thechildrenin between the Header and Footer components. When you wrap a page with this Layout, the Header, and Footer will be displayed at the top and bottom.

Using the Layout Component
To use the layout component, import it into a page component and use it as shown below.
It will apply the layout to this page. You can repeat this process to all the pages you want to apply the layout.
To use the layout across all the pages in the applications at once, import the layout component into the/page/_app.jsfile and use it as follows.
The examples shown so far use the Next.js 12 pages folders. In Next.js 13, you create the layout in the app folder (as of writing, it’s in beta).
![]()
Creating a Custom Layout in the App Folder
Theapp folder in Next.js 13requires you to create a root layout at its base. This is the layout that Next.js will apply to all the pages of your application.
To demonstrate, create a file namedlayout.jsxand add the following code.
![]()
The root layout component accepts and renders thechildren. Below are some of the things you should know about a root layout:
As mentioned, the root layout applies to all pages, so how do you create custom layouts for different route segments?

In your app folder, you can define a route by creating folders for each route segment. For example, creating a folder calledarticlesmaps to the URL pathapp/articles. To add further route segments, create a subfolder within the main route folder. For instance, adding a folder calledtrendinginside thearticlesfolder maps to the URL pathapp/articles/trending.
When you add alayout.jsxcomponent to a route folder, it will apply to all pages within that route segment and its subfolders. For example, adding a layout component to thearticlesfolder will apply to all pages in the articles route, including those in thetrendingsubfolder. If you also add a layout component in thetrendingfolder, the layout in the articles folder will be nested within it.
Advantages of Using Layouts
Next.js enables you to create layout components it’s possible to reuse across different pages. This allows you to have a consistent look across your website without duplicating code across multiple pages. Additionally, layouts help you implement changes quickly because you don’t need to make changes to each page.
Next.js gives you fast, flexible apps that you can get set up in no time. Find out just why it’s fast becoming one of the most popular web frameworks.
You don’t need to fork out for expensive hardware to run an AI on your PC.
It’s not super flashy, but it can help to keep your computer up and running.
OneDrive is one of the best, but it has a catch.
The best features aren’t the ones being advertised.
These plugins will make you wonder why you used Photoshop in the first place.