What Are VS Code Snippets?
A snippet is a template that lets you type a short keyword — called a prefix — and press Tab to expand it into a full block of code. Type html5 and Tab to get a complete HTML boilerplate. Type arw and Tab for an arrow function.
Snippets inside an extension are more powerful than user snippets because they can be shared, packaged as .vsix, and installed on any VS Code setup.
The Snippet JSON Format
{
"HTML5 Boilerplate": {
"prefix": "html5",
"body": [
"<!DOCTYPE html>",
"<html lang=\"en\">",
"<head>",
"\t<meta charset=\"UTF-8\" />",
"\t<title>${1:Document Title}</title>",
"</head>",
"<body>",
"\t$0",
"</body>",
"</html>"
],
"description": "Full HTML5 boilerplate",
"scope": "html"
}
}
Tab Stops and Placeholders
- ✓
$1,$2,$3— Tab stops. Press Tab to jump from one to the next. - ✓
${1:text}— Placeholder with default text the user can type over. - ✓
$0— The final cursor position after all tab stops.
Scoping Snippets to Specific Languages
{
"Console Log": {
"prefix": "log",
"body": ["console.log($1);"],
"scope": "javascript,typescript"
}
}
The scope field controls which file types the snippet appears in. Our pack covers four languages:
- ✓HTML — boilerplate, forms, cards, navbars, tables, meta tags
- ✓CSS — flexbox, grid, media queries, custom properties
- ✓JavaScript — arrow functions, async/await, fetch, localStorage, event listeners
- ✓PHP — echo, foreach, function definitions
Installing Your Snippet Pack
vsce package
# Creates: yfin-snippets-1.0.0.vsix
Then in VS Code: Ctrl+Shift+P → Install from VSIX → select the file.
This is a preview. The full ebook includes all 22 complete snippets with code, a test checklist for every snippet, and tips on creating your own custom snippets beyond the ones included.
