![Kayce Basques](https://web.dev/images/authors/kaycebasques.jpg) Kayce Basques [X](https://twitter.com/kaycebasques) [GitHub](https://github.com/kaycebasques) ![Sofia Emelianova](https://web.dev/images/authors/sofiayem.jpg) Sofia Emelianova [GitHub](https://github.com/sofiayem)

<br />

[Video](https://www.youtube.com/watch?v=zW9ibQbYJNE)

If you find yourself running the same code in the [**Console**](https://developer.chrome.com/docs/devtools/console.md.txt) repeatedly, consider saving the code as a snippet instead. Snippets have access to the page's JavaScript context. They are an alternative to [bookmarklets](https://en.wikipedia.org/wiki/Bookmarklet).

You can author snippets in the [**Sources** panel](https://developer.chrome.com/docs/devtools/javascript/sources) and run them on any page and in incognito mode.

> [!NOTE]
> **Note:** DevTools stores snippets as your local preferences. DevTools doesn't [sync](https://developer.chrome.com/docs/devtools/customize.md.txt#sync) snippets with settings and they can't be accessed via the file system.

For example, the screenshot below shows the DevTools documentation homepage on the left and some snippet source code in the **Sources \> Snippets** pane on the right.

![The DevTools documentation homepage before running the snippet. The Run button is highlighted.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/the-devtools-documentatio-b98254f550319.png)

Here's the snippet source code that [logs some message](https://developer.chrome.com/docs/devtools/console/log.md.txt) and replaces the homepage's HTML body with a `<p>` element that contains the message:

```javascript
console.log('Hello, Snippets!');
document.body.innerHTML = '';
const p = document.createElement('p');
p.textContent = 'Hello, Snippets!';
document.body.appendChild(p);
```

When you click the ![Run.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/run-2470fa9d1dbe8.svg) **Run** button, the [**Console** drawer](https://developer.chrome.com/docs/devtools/console.md.txt) pops up to display the `Hello, Snippets!` message that the snippet logs, and the page's content changes.

![The homepage after running the snippet.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/the-homepage-running-sn-9f8f2c8d23f98.png)

## Open the Snippets pane

The **Snippets** pane lists your snippets. To edit a snippet, open it in one of two ways:

1. Navigate to **Sources \> ![More tabs.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/more-tabs-fd06550cc62e1.svg) \> Snippets**.

   ![The More tabs menu on the Sources pane.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/the-more-tabs-menu-the-s-97d9b7b808e0d.png)
2. From the [**Command Menu**](https://developer.chrome.com/docs/devtools/command-menu.md.txt):

   1. Press <kbd>Control</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Windows/Linux) or <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Mac) to open the **Command Menu**.
   2. Start typing `Snippets`, select **Show Snippets** , and press <kbd>Enter</kbd>.

   ![Selecting Show Snippets from the Command Menu.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/selecting-show-snippets-75a3b0007b1a3.png)

The **Sources** \>**Snippets** pane shows you a list of snippets you saved, empty in this example.

![An empty Snippets pane.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/an-empty-snippets-pane-8e9a4096c77b4.png)

## Create snippets

You can create snippets in the **Snippets** pane or by running the corresponding command from the **Command Menu** anywhere in DevTools.

The **Snippets** pane sorts your snippets in alphabetical order.

### Create a snippet in the Sources panel

1. [Open the **Snippets** pane](https://developer.chrome.com/docs/devtools/javascript/snippets.md.txt#open).
2. Click ![New snippet.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/new-snippet-ed057e67dd709.svg) **New snippet**.
3. Enter a name for your snippet and press <kbd>Enter</kbd> to save.

   ![Naming a snippet.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/naming-snippet-591ec3e9813ec.png)

### Create a snippet from the Command Menu

1. Focus your cursor anywhere inside of DevTools.
2. Press <kbd>Control</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Windows/Linux) or <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Mac) to open the **Command Menu**.
3. Start typing `Snippet`, select **Create new snippet** , then press <kbd>Enter</kbd> to run the command.

   ![Selecting Create new snippet from the Command Menu.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/selecting-create-snippet-31570905b942a.png)

See [Rename snippets](https://developer.chrome.com/docs/devtools/javascript/snippets.md.txt#rename) if you'd like to give your new snippet a custom name.

## Edit snippets

1. [Open the **Snippets** pane](https://developer.chrome.com/docs/devtools/javascript/snippets.md.txt#open).
2. In the **Snippets** pane, click the name of the snippet that you want to edit. The **Sources** panel opens it in the **Code Editor**.

   ![A snippet opened in the Code Editor.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/a-snippet-opened-the-cod-4c0c19e63990f.png)
3. Use the **Code Editor** to edit code in your snippet. An asterisk next to the snippet name means that you haven't saved your changes yet.

   ![An asterisk next to the snippet name that indicates unsaved code.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/an-asterisk-next-the-sni-1b732bf1b049b.png)
4. Press <kbd>Control</kbd>+<kbd>S</kbd> (Windows/Linux) or <kbd>Command</kbd>+<kbd>S</kbd> (Mac) to save.

## Run snippets

Similar to creating a snippet, you can run it both in the **Snippets** pane and from the **Command Menu**.

### Run a snippet in the Sources panel

1. [Open the **Snippets** pane](https://developer.chrome.com/docs/devtools/javascript/snippets.md.txt#open).
2. Click the name of the snippet you want to run. The **Sources** panel opens it in the **Code Editor**.
3. Click ![Run.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/run-de91854eb37cb.svg) **Run** in the action bar at the bottom of the editor,
   or press <kbd>Control</kbd>+<kbd>Enter</kbd> (Windows/Linux) or <kbd>Command</kbd>+<kbd>Enter</kbd> (Mac).

   ![The Run button.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/the-run-button-c4816726a777b.png)

### Run a snippet from the Command Menu

1. Focus your cursor anywhere inside of DevTools.
2. Press <kbd>Control</kbd>+<kbd>O</kbd> (Windows/Linux) or <kbd>Command</kbd>+<kbd>O</kbd> (Mac) to open the **Command Menu**.
3. Type the `!` character followed by the name of the snippet that you want to run.

   ![Running a snippet from the Open Menu.](https://developer.chrome.com/static/docs/devtools/javascript/snippets/image/running-snippet-the-ope-cd6f92d9a3e8e.png)
4. Press <kbd>Enter</kbd> to run the snippet.

## Rename snippets

1. [Open the **Snippets** pane](https://developer.chrome.com/docs/devtools/javascript/snippets.md.txt#open).
2. Right-click the snippet name and select **Rename**.

## Delete snippets

1. [Open the **Snippets** pane](https://developer.chrome.com/docs/devtools/javascript/snippets.md.txt#open).
2. Right-click the snippet name and select **Remove**.