Introduction
As a developer, efficiency and speed are crucial. Visual Studio Code (VSCode) allows you to create custom snippets to reduce repetitive tasks and save time. In this article, we’ll walk you through adding a set of SCSS snippets to VSCode. These snippets are designed to help streamline your workflow when working with media queries, container queries, and loops in SCSS.
For this example I’ll make snippets for the media/container queries (see article).
Adding Snippets to VSCode
Follow these steps to add the provided snippets to VSCode:
- Open VSCode: Launch your VSCode editor.
- Access User Snippets:
- Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(Mac) to open the command palette. - Type “Preferences: Configure User Snippets” and select it.
- Press
- Create or Edit SCSS Snippets:
- In the snippet selector, type
scssand select thescss.jsonfile if it exists. If it doesn’t, create a newscss.jsonfile.
- In the snippet selector, type
- Add Snippets:
- Copy the following JSON and paste it into the
scss.jsonfile:
- Copy the following JSON and paste it into the
{
"Media query up": {
"prefix": "@up",
"body": [
"@include media-breakpoint-up($1) {",
"$2",
"}",
],
"description": "Media query up"
},
"Media query down": {
"prefix": "@down",
"body": [
"@include media-breakpoint-down($1) {",
"$2",
"}",
],
"description": "Media query down"
},
"Media query only": {
"prefix": "@only",
"body": [
"@include media-breakpoint-only($1) {",
"$2",
"}",
],
"description": "Media query only"
},
"Container query up": {
"prefix": "@contup",
"body": [
"@include container-breakpoint-up($1) {",
"$2",
"}",
],
"description": "Container query up"
},
"Container query down": {
"prefix": "@contdown",
"body": [
"@include container-breakpoint-down($1) {",
"$2",
"}",
],
"description": "Container query down"
},
"Container query only": {
"prefix": "@contonly",
"body": [
"@include container-breakpoint-only($1) {",
"$2",
"}",
],
"description": "Container query only"
},
"Property": {
"prefix": "@prop",
"body": [
"@property --$1 {",
"syntax: '<$2>';",
"initial-value: $3;",
"inherits: $4;",
"}",
],
"description": "Container query only"
}
}
Using the Snippets in VSCode
To use the snippets you’ve added:
- Open an SCSS File: Open any
.scssfile in VSCode. - Trigger the Snippet:
- Type the prefix for the desired snippet (e.g.,
@upfor Media Query Up). - VSCode will suggest the snippet as you type. Press
EnterorTabto insert the snippet.
- Type the prefix for the desired snippet (e.g.,
- Fill in the Placeholder Values:
- After inserting the snippet, you’ll see placeholders like
$1,$2, etc - Navigate through the placeholders using
Taband fill in the required values.
- After inserting the snippet, you’ll see placeholders like
Conclusion
Adding custom snippets in VSCode can significantly enhance your productivity by reducing repetitive coding tasks. With these SCSS snippets, you can handle media queries and container queries efficiently. If you find a little bit of code that you use frequently, You can now put It as a snippet.

Leave a Reply