Sass - Interpolation


It provides SassScript variables in selectors and property names using #{ } syntax. You can specify variables or property names within the curly braces.



Where $name is the name of the variable or property name.


The following example demonstrates the use of interpolation in the SCSS file −

      <link rel = "stylesheet" type = "text/css" href = "style.css" />
      <link rel = "stylesheet" href = "">
      <script src = ""></script>
      <script src = ""></script>

      <div class = "container">
         <h2>Example using Interpolation</h2>
         <p>SASS stands for Syntactically Awesome Stylesheet...</p>

Next, create file style.scss.


p:after {
   content: "I have #{8 + 2} books on SASS!";

You can tell SASS to watch the file and update the CSS whenever SASS file changes, by using the following command −

sass --watch C:\ruby\lib\sass\style.scss:style.css

Next, execute the above command; it will create the style.css file automatically with the following code −


p:after {
   content: "I have 10 books on SASS!";


Let us carry out the following steps to see how the above given code works −

  • Save the above given html code in interpolation.html file.

  • Open this HTML file in a browser, an output is displayed as shown below.

Sass Interpolation