What is a Snippet?
A snippet is a reusable code fragment with variables you fill in when using it:- Boilerplate code you type often
- Patterns with different values each time
- Team-standard code structures
- Quick utilities
Creating a Snippet
1
Go to Snippets
Click Snippets in the sidebar navigation.
2
Click New Snippet
Click the New Snippet button.
3
Fill in details
- Name: What this snippet does (e.g., “Track Event”)
- Description: When to use it
- Language: JavaScript or CSS
- Category: For organization
4
Write the template
Write your code using
{{variableName}} for placeholders:5
Define variables
For each variable, specify:
- Description: What value to enter
- Default value: Pre-filled suggestion
- Required: Whether it must be filled
6
Save
Click Save to create the snippet.
Using Variables
Syntax
Use double curly braces for variables:Variable Names
Use descriptive camelCase names:Repeated Variables
Use the same variable name multiple times—it fills in everywhere:modal for {{elementName}}, all three instances update.
Inserting a Snippet
1
Open a script
Go to your site and open a script in the editor.
2
Click Insert Snippet
Click the Insert Snippet button in the toolbar.
3
Find your snippet
Search or browse for the snippet you want.
4
Fill in variables
Enter values for each variable. Defaults are pre-filled.
5
Insert
Click Insert. The code is added at your cursor position.
Example Snippets
Event Listener
selector: CSS selector (default:.button)event: Event type (default:click)code: Handler code (default:console.log('clicked'))
Intersection Observer
selector: Elements to observe (default:[data-animate])visibleClass: Class when visible (default:is-visible)threshold: Visibility threshold (default:0.1)
Fetch API Call
url: API endpointmethod: HTTP method (default:POST)body: Request body (default:{})successHandler: Success code (default:console.log(data))
CSS Animation
animationName: Name for keyframes (default:fadeIn)className: Class to animate (default:animate)duration: Animation duration (default:0.3s)easing: Timing function (default:ease-out)fromProperties: Starting styles (default:opacity: 0)toProperties: Ending styles (default:opacity: 1)
Snippets vs Blocks
| Feature | Snippet | Block |
|---|---|---|
| Variables | Yes, fill-in placeholders | No |
| Installation | Inserted into scripts | Creates new script |
| Size | Small code fragments | Complete features |
| Use case | Templates, patterns | Reusable components |
Sharing Snippets
Within Your Team
All snippets are automatically available to team members.Publicly
Make snippets available to all users:- Open the snippet
- Toggle Make Public
- The snippet appears in the public library
Best Practices
Keep snippets small and focused
Keep snippets small and focused
Snippets work best for small patterns. If you’re creating large blocks of code, consider using a Block instead.
Use descriptive variable names
Use descriptive variable names
Variable names should make it clear what value to enter:
Provide helpful defaults
Provide helpful defaults
Good defaults help users understand expected values and speed up insertion.
Add descriptions to variables
Add descriptions to variables
Explain what each variable is for, especially if it’s not obvious.
Organize with categories
Organize with categories
Use categories to group related snippets:
- Events
- DOM Manipulation
- Animations
- API Calls