# Editing theme code

<aside class="note note-caution"><h4>Caution</h4><p>If changes that you&#39;ve made to a theme&#39;s code are incompatible with a theme update, then all your code changes are removed in the updated copy. You should only edit your theme&#39;s code if you can&#39;t make the changes that you need by using a Shopify app or by using the theme editor.</p>
</aside>

You can edit your theme code to make detailed changes to your online store with the code editor. Most of the files that make up a theme contain [Liquid](https://shopify.dev/api/liquid), Shopify's templating language. Theme files also contain HTML, CSS, JSON, and JavaScript. Edit the code for a theme only if you know HTML and CSS, and have a basic understanding of Liquid.

You can edit your theme's code only after you've purchased it. This includes using the AI code generator in the theme editor. If you're using a trial version of a paid theme, then you need to purchase it before you can make code changes.

<aside class="note note-growth"><h4>Grow your business</h4><p>If you want to add custom features or code but don&#39;t have experience developing websites with HTML, CSS, and JavaScript, then consider hiring a <a href="/en/manual/partner-directory">Shopify Partner</a>.</p>
</aside>

<aside class="note note-caution"><h4>Caution</h4><p>To prepare for customizing your theme, complete the following recommended tasks:</p>
<ul>
<li><a href="/en/manual/online-store/themes/managing-themes/duplicating-themes">Duplicate your theme</a> to create a backup copy. This makes it easy to discard your changes and start again if you need to.</li>
<li>Make sure that you understand what <a href="/en/manual/online-store/themes/theme-support">level of support</a> is available.</li>
<li>Learn about the requirements and best practices for <a href="/en/manual/online-store/images/theme-images">uploading images</a>.</li>
</ul>
</aside>


The code editor displays a directory of your theme's files, and a space to display and edit the files. When you click a file in the directory, it opens in the code editor. You can open and edit multiple files at the same time. You can also open and review multiple files at the same time.

![The theme code editor layout](/manual/themes/theme-code-editor/code-editor.png)

## Edit your theme code {#edit-your-theme-code}

You can use the code editor to modify your theme's files.

#### Steps:

<div class="sections"><details open><summary id="desktop">Desktop</summary><ol>
<li><p>From your Shopify admin, go to <a href="https://admin.shopify.com/themes"><strong>Online Store</strong></a>.</p>
</li>
<li><p>Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> &gt; <strong>Edit code</strong>.</p>
</li>
</ol>
</details><details><summary id="mobile">Mobile</summary><ol>
<li><p>From the <a href="https://www.shopify.com/install/detect">Shopify app</a>, tap the <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuIcon.svg" alt="Menu" class="admin-icon" /> icon.</p>
</li>
<li><p>In the <strong>Sales channels</strong> section, tap <strong>Online Store</strong>.</p>
</li>
<li><p>Tap <strong>Manage themes</strong>.</p>
</li>
<li><p>Tap <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> &gt; <strong>Edit code</strong>.</p>
</li>
</ol>
</details></div>

## Saving changes

When you edit a file, a dot displays next to the tab name to indicate unsaved changes. Click the **Save** button to save your changes. You can also enter <code>&#8984;</code> + `S` on Mac or `Ctrl` + `S` on Windows to save your changes.

![A partial code editor showing an unsaved file next to the save button](/manual/themes/theme-code-editor/save-file.png)

## Formatting theme code {#format-code}

To fix code indentation, open the Command Palette with <code>&#8984;</code> + `Shift` + `P` on Mac or `Ctrl` + `Shift` + `P` on Windows `format`, and then select **Format document**.

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Open the file that you want to format.
3. Enter <code>&#8984;</code> + `P` on Mac or `Ctrl` + `P` on Windows.
4. In the command palette, enter <kbd>format</kbd>, then press `Enter` on your keyboard.
5. Save the file.

![Command palette with the code formatting option selected](/manual/themes/theme-code-editor/format-file.png)

### Tracking file changes {#roll-back}

To restore a modified theme file to a previous version, use the **Timeline** view for that file.

The **Timeline** view restores one existing file at a time. It doesn't restore an entire theme, and it can't recover deleted theme files. Timeline history is finite, so older versions might not be available.

Restoring replaces the whole file contents, including changes you might want to keep. Before restoring a file, copy the current file contents somewhere safe if you might want to keep any changes.

![Version control in the theme editor](/manual/themes/theme-code-editor/version-control.png)

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Open the existing file that you want to review or restore.
4. Optional: If you might want to keep any current changes, copy the current file contents somewhere safe before restoring.
5. In the **Timeline** view, click an entry in the timeline to compare the differences.
6. To replace the whole file contents with the selected previous version, right-click the timeline entry, and then select **Restore contents**.
7. Click **Restore**.

## Theme Check {#theme-check}

The code editor includes Theme Check, a feature that helps to prevent errors by providing immediate feedback as the code is being written, instead of discovering errors in your live theme.

In the code editor, Theme Check can identify the following errors in edited code:

* Parser blocking scripts, which can slow down a storefront
* Inconsistencies between translation files, such as missing translation keys or translations that don't match in a locale file
* Missing templates

Errors are indicated by a red line underneath the code. To view the error, hover your mouse over the highlighted line.

## Searching and replacing in the code editor

You can search within the code editor in either of the following ways:

* Search the code of a specific file.
* Search the code of all files in the theme.

You can also replace code in a specific file or multiple instances across all theme files. You can also search for a file by name to [open a file](/manual/online-store/themes/customizing-themes/edit-code/edit-theme-code#open-file).

### Searching within a file {#search-file}

You can search the code in a specific file, and replace the code. Use the arrow keys to review each instance of the code.

![The search UI within a file in the code editor](/manual/themes/theme-code-editor/search-file.png)

After you search for code, you can replace the code in a file. 

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Open the file that you want to search. 
4. Enter <code>&#8984;</code> + `F` on a Mac or `Ctrl` + `F` on Windows.
4. In the **Search** field, enter your search term.
5. Optional: To replace code, complete the following actions:
  * In the search modal, click the <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/ChevronRightIcon.svg" alt="Right arrow" class="admin-icon" /> icon.
  * In the **Replace** field, enter the replacement code. You can click **Preserve case** to match the replacement code's capitalization to the existing instance.
  * Click the **Replace** icon to replace instance at a time, or click the **Replace all** icon to replace all instances at one time.

### Searching across all files {#search-all-files}

Click the search button in the left sidebar to search across all theme files. Results display every instance of your search term and which file it appears in.

![The search side panel in the code editor](/manual/themes/theme-code-editor/search-theme.png)

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Click the <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/SearchIcon.svg" alt="Search" class="admin-icon" /> icon to open the search panel. 
4. In the **Search** field, enter your search term.
5. Optional: To replace code, complete the following actions:
  * In the search modal, click the <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/ChevronRightIcon.svg" alt="Right arrow" class="admin-icon" /> icon.
  * In the **Replace** field, enter the replacement code.
  * Replace one instance at a time, or all instances at one time.

### Advanced search options

To narrow down your search results, use one or more of the following search options: 

* **Match case** returns search terms that match the case. For example, if you enter <kbd>product</kbd>, then the search highlights any instances of "product" or "Product". If you select **Match case**, then the search highlights instances of <kbd>product</kbd> only.
* **Match Whole Word** returns search terms that match the exact word, and excludes partial matches. For example, if you enter <kbd>cart</kbd>, then the search highlights instances of "cart" but not "carton".
* **Use Regular Expression** returns search results that match a regular expression (regex). A _regex_ is a string of characters that specifies a match pattern in text. 

<aside class="note note-caution"><h4>Caution</h4><p>Using regex is an advanced customization technique. You can use a third-party tool such as <a href="https://regex101.com/">regex101</a> or <a href="https://regexr.com/">RegExr</a> for guidance on building a regex string.</p>
</aside>

In the **Search** panel, you can also select files and folders to include or exclude from the search results.

Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> to open the advanced menu. You can enter any file or folder path in the **files to include** or **files to exclude** fields. To add more than one file or folder, separate them with a space and comma. For example, to search for files in the **sections** folder, enter <kbd>./sections</kbd> in **files to include** field.

You can also search within a specific folder from the file directory view. Right-click on a folder, and then select **Find in folder...** from the dropdown menu.

## Managing theme files

You can manage files in your theme code. You can delete files, add new files, rename files, and restore modified existing code files from their **Timeline** view when a previous version is available. Asset files, such as images, CSS, JavaScript, and fonts in the **assets** folder, don't have Timeline history.

### Opening a theme file {#open-file}

To open a theme file, click on a folder, and then click on the file name from the explorer. You can also search for files by name or extension, and then open the file.

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Enter <code>&#8984;</code> + `P` on Mac or `Ctrl` + `P` on Windows.
4. Enter the file name in the search bar and select the file, or select a file from the **Recently opened** list.

### Adding a new theme file {#add-file}

To add a file, select a folder, click the **New file** icon, and then enter the file name and file extension.

File names can include characters A-Z, 0-9, and can't include character spaces. Separate words by dashes or underscores. A file extension is defined by a period `.` and the extension type. For example, `.liquid` or `.css`. 
 
#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Click the folder that you want to add a new file to.
4. Right-click the folder name and select **New file...** from the drop-down menu.
4. Enter a new name for the file.
5. Press `Enter` on your keyboard.

### Uploading a new asset {#upload-asset}

You can upload a new asset, such as an icon or image file, to the **assets** folder of the code editor.

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Right-click on the **assets** folder.
4. Click **Upload...**.
5. Select the file that you want to upload.
6. Click **Open**.

### Renaming a theme file {#rename-file}

You can right-click a file to rename it. Make sure not to edit or remove the file extension. A file extension is defined by a period `.` and the extension type. For example, `.liquid` or `.css`. File names can include characters A-Z, 0-9, and can't include character spaces. Separate words by dashes or underscores. If the filename isn't valid, then the new file name won't save.

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Right-click on a file and select **Rename...** from the drop-down menu.
4. Enter a new name for the file.
5. Press `Enter` on your keyboard.

### Deleting a theme file {#delete-file}

<aside class="note caution"><h4>Caution</h4><p>Deleting a theme file might break your theme. Before you delete any file, make sure to make a <a href="/en/manual/online-store/themes/managing-themes/duplicating-themes">duplicate of your theme</a>.</p>
</aside>

You can delete any files in your theme. Deleted theme files can't be recovered.

#### Steps:

1. From your Shopify admin, go to [**Online Store**](https://admin.shopify.com/themes).


2. Click <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuHorizontalIcon.svg" alt="Horizontal menu" class="admin-icon" /> > **Edit code**.
3. Right-click on a file and select **Delete permanently** from the drop-down menu.
4. Click **Delete**.
