![]() |
SASS is a strong CSS preprocessor that adds a number of features to improve the usability and maintainability of stylesheets. Variable interpolation is one such feature that permits the dynamic insertion of variable values into selectors and properties. In this article, we will learn the variable interpolation in Sass. Variable InterpolationIt is a SASS feature that developers can use to dynamically inject the value of a variable into selectors and properties. It can be done by utilizing the ‘#{}‘ syntax. Developers can create dynamic stylesheets by using static text with variable values via variable interpolation. Features of Variable Interpolation using SASS:
Syntax:$variable: value; // Variable Interpolation in selectors .#{$variable}-text { property: $variable; } // Variable Interpolation in properties .button { background-color: #{$variable}; border: 1px solid #{$variable}; } For a detailed Installation process of the SASS in the project, refer to the Installation of SASS article. Example 1: The code example shows how we can use the Variable Interpolation in properties and use different variables for them
HTML
CSS
When the above code is compiled into CSS using the SASS preprocessor: sass styles.scss style.css
CSS
Output: Example 2: The code example shows how we can use the Variable Interpolation in properties and selectors using different variables in them:
HTML
CSS
When the above code is compiled into CSS using the SASS preprocessor: sass styles.scss style.css
CSS
Output: |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |