Math with interpolated variables?

Sass cannot perform arithemetic operations on strings, only concatenation. When you use interpolation, what you’ve created is a string that looks like a number:

@debug type-of(#{10px});         // string
@debug type-of('10px');          // string
@debug type-of(unquote('10px')); // string
@debug type-of(10px);            // number

If you want a number, do not use interpolation and do not use quotes. For converting an integer (eg. 10) to a length (eg. 10px), use multiplication:

$gutter-em: ($gutter / $em) * 1em;
@debug type-of($gutter-em);      // number

Leave a Comment