---
title: "Adding Response Headers in Edge Middleware"
description: "Learn to add response headers at the edge."
url: "https://vercel.com/templates/next.js/edge-functions-add-header"
links:
  repository: "https://github.com/vercel/examples/tree/main/edge-middleware/add-header"
  demo: "https://edge-functions-add-header.vercel.app"
  deploy: "https://vercel.com/new/clone?demo-title=Adding+Response+Headers+in+Edge+Middleware&demo-description=Learn+to+add+response+headers+at+the+edge.&demo-url=https%3A%2F%2Fedge-functions-add-header.vercel.app&project-name=add-header&repository-name=add-header&repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fedge-middleware%2Fadd-header&demo-image=%2F%2Fimages.ctfassets.net%2Fe5382hct74si%2F2TxIjk2N6U2bx48Ub1mIh9%2Fc7451bd7aaaca9b66a967f0782ab8005%2Fedge-functions-add-header.vercel.app_.png"
---

# Adding Response Headers in Edge Middleware

Learn to add response headers at the edge.

# Add Header Example

Below is the code from [middleware.ts](https://github.com/vercel/examples/tree/main/edge-middleware/add-header/middleware.ts) showing how to add response headers at the edge:

```ts
import { NextResponse } from 'next/server'

export default function middleware() {
  // Store the response so we can modify its headers
  const response = NextResponse.next()

  // Set custom header
  response.headers.set('x-modified-edge', 'true')

  // Return response
  return response
}
```

## Demo

https://edge-functions-add-header.vercel.app

## How to Use

You can choose from one of the following two methods to use this repository:

### One-Click Deploy

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/add-header&project-name=add-header&repository-name=add-header)

### Clone and Deploy

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [pnpm](https://pnpm.io/installation) to bootstrap the example:

```bash
pnpm create next-app --example https://github.com/vercel/examples/tree/main/edge-middleware/add-header add-header
```

Next, run Next.js in development mode:

```bash
pnpm dev
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=edge-middleware-eap) ([Documentation](https://nextjs.org/docs/deployment)).

## Related Templates

### [Next.js Boilerplate](https://vercel.com/templates/next.js/nextjs-boilerplate)

Get started with Next.js and React in seconds.

---

## Additional documentation

The [Vercel Knowledge Base](https://vercel.com/kb) contains guides and answers to common questions about Vercel, including deployment, framework configuration, domains, caching, and troubleshooting.
