> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/build/code-in-n8n/define-custom-variables.md).

# Define custom variables

{% hint style="info" %}
**Feature availability**

* Available on Self-hosted Enterprise and Pro Cloud plans.
* Only instance owners and admins can create variables.
  {% endhint %}

Custom variables are read-only variables that you can use to store and reuse values in n8n workflows.

{% hint style="warning" %}
**Variable scope and availability**

* **Global variables** are available to everyone on your n8n instance, across all projects.
* **Project-scoped variables** are available only within the specific project they're created in.
* Project-scoped variables are available in 1.118.0 and above. Previous versions only support global variables accessible from the left side menu.
  {% endhint %}

## Create variables <a href="#create-variables" id="create-variables"></a>

You can access the **Variables** tab from either the overview page or a specific project.

To create a new variable:

1. On the **Variables** tab, select **Add Variable**.
2. Enter a **Key** and **Value**. The maximum key length is 50 characters, and the maximum value length is 1000 characters. n8n limits the characters you can use in the key and value to lowercase and uppercase letters, numbers, and underscores (`A-Z`, `a-z`, `0-9`, `_`).
3. Select the **Scope** (only available when creating from the overview page):
   * **Global**: The variable is available across all projects in the n8n instance.
   * **Project**: The variable is available only within a specific project (you can select which project).
   * When creating from a project page, the scope is automatically set to that project.
4. Select **Save**. The variable is now available for use in workflows according to its scope.

## Edit and delete variables <a href="#edit-and-delete-variables" id="edit-and-delete-variables"></a>

To edit or delete a variable:

1. On the **Variables** tab, hover over the variable you want to change.
2. Select **Edit** or **Delete**.

## Use variables in workflows <a href="#use-variables-in-workflows" id="use-variables-in-workflows"></a>

You can access variables in the Code node and in expressions[^1]:

```javascript
// Access a variable
$vars.<variable-name>
```

All variables are strings.

During workflow execution, n8n replaces the variables with the variable value. If the variable has no value, n8n treats its value as `undefined`. Workflows don't automatically fail in this case.

{% hint style="info" %}
**Variable precedence**

When a project-scoped variable has the same key as a global variable, the project-scoped variable value takes precedence and overrides the global variable value within that project's workflows.
{% endhint %}

Variables are read-only. You must use the UI to change the values. If you need to set and access custom data within your workflow, use [Workflow static data](/build/code-in-n8n/cookbook/built-in-methods-and-variables-examples/getworkflowstaticdata.md).

[^1]: In n8n, expressions allow you to populate node parameters dynamically by executing JavaScript code. Instead of providing a static value, you can use the n8n expression syntax to define the value using data from previous nodes, other workflows, or your n8n environment.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/build/code-in-n8n/define-custom-variables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
