You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Snippets in Azure Static Web Apps (preview)
3
+
description: Inject custom code in the HEAD or BODY elements at runtime in Azure Static Web Apps
4
+
services: static-web-apps
5
+
author: craigshoemaker
6
+
ms.service: static-web-apps
7
+
ms.topic: overview
8
+
ms.date: 06/22/2023
9
+
ms.author: cshoe
10
+
---
11
+
12
+
# Snippets in Azure Static Web Apps (preview)
13
+
14
+
Azure Static Web Apps allows you to inject custom code into the `head` or `body` elements at runtime. These pieces of code are known as "snippets".
15
+
16
+
Common use cases of snippets include:
17
+
18
+
- Analytics scripts
19
+
- Common scripts
20
+
- Global UI elements
21
+
22
+
## Add a snippet
23
+
24
+
1. Go to your static web app in the Azure portal.
25
+
26
+
1. From the *Settings* menu, select **Configuration**.
27
+
28
+
1. Select the **Snippets** tab.
29
+
30
+
1. Enter the following settings in the Snippets window:
31
+
32
+
| Setting | Value | Comments |
33
+
|---|---|--|
34
+
| Location | Select which element as the destination for your code. ||
35
+
| Name | Enter a snippet name. ||
36
+
| Insertion location | Select whether you want to **Prepend** or **Append** your code to the selected element. | Prepend means your code appears directly after the open tag of the element. Append means your code appears directly before the close tag of the element. |
37
+
| Environment | Select the environment(s) you want to target. | If you select **Select environment** then you can choose a selection of environments to target. |
0 commit comments