How to Create Your Own Layout Component in Vue.js

A guide on how to create basic layout components with Header, Footer, and content section.

Layout Component

Components are reusable independent pieces of your application UI. The layout component is a component used to share a common section across multiple pages. The layout component mostly will have the common header, sidebar, and footer section.

    1. Create App
    1. Folder structure
    1. Create Header Component
    1. Create Footer component
    1. Create Layout component
    1. Add Layout to the Root component

1. Create App

Create your Vite-powered Vue project using the create-vue

npm init vue@latest✔ Project name: … <your-project-name>
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit testing? … No / Yes
✔ Add Cypress for both Unit and End-to-End testing? … No / Yes
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes

Scaffolding project in ./<your-project-name>...

If you are unsure about an option, simply choose No by hitting enter for now. Once the project is created, follow the instructions to install dependencies and start the dev server:

> cd <your-project-name>
> npm install
> npm run dev

2. Folder structure

Create the Layout folder inside the components folder. Also, create the Header and Footer components.

3. Create Header Component

Create your header and footer components using the below code:


export default {
  name: 'Header'

4. Create Footer component



export default {
  name: 'Footer'

5. Create Layout component

Now we going to create our Layout component. Import the Header and Footer components into the Layout component. The<slot> is used to display the content of the component.


    <Header />
    <slot />
    <Footer />

import Header from './Header/Header.vue'
import Footer from './Footer/Footer.vue'

export default {
  name: 'Layout',
  components: {

6. Add Layout to the Root component

The App component is a root component of our application. Add the layout to the root component.


  <div id="app">
      <img alt="Vue logo" src="">
      <HelloWorld msg="Welcome to Your Vue.js App"/>

import HelloWorld from './components/HelloWorld.vue'
import Layout from './components/Layout/Layout.vue'

export default {
  name: 'App',
  components: {


This example code is available at

StackBlitz application

We successfully created our own layout component. This is a basic Vue.js layout component, hope it will help you to understand the basic layout flow.

Thank you for reading.

Continue Learning