📖 Scenario: You are creating styles for a website header. You want to use Sass strings to store parts of the header text and then combine them to form the full header title.
🎯 Goal: Build a Sass stylesheet that defines string variables and concatenates them to create a full header title.
📋 What You'll Learn
Use Sass string variables
Concatenate strings using Sass syntax
Assign the concatenated string to a variable
Use the final string in a CSS rule
💡 Why This Matters
🌍 Real World
Web designers often need to combine text parts dynamically in stylesheets for headers, labels, or buttons.
💼 Career
Knowing how to manipulate strings in Sass helps create flexible and maintainable CSS for professional web projects.
Progress0 / 4 steps
1
Create string variables
Create two Sass string variables called $part1 and $part2 with the exact values "Welcome to" and "My Website" respectively.
SASS
Hint
Use $variable-name: "string value"; to create string variables in Sass.
2
Add a space string variable
Create a Sass string variable called $space with the exact value of a single space character " ".
SASS
Hint
Remember to put the space inside quotes to make it a string.
3
Concatenate strings
Create a Sass variable called $full-title that concatenates $part1, $space, and $part2 using the #{} interpolation syntax inside double quotes.
SASS
Hint
Use "#{$var1}#{$var2}" to join strings in Sass.
4
Use the concatenated string in CSS
Create a CSS rule for the header element that sets the content property of a ::before pseudo-element to the Sass variable $full-title using interpolation.
SASS
Hint
Use content: "#{$variable}"; inside the CSS rule to insert the string.
Practice
(1/5)
1. Which of the following is a valid way to define a quoted string in Sass?
easy
A. content: "Hello World";
B. content: Hello World;
C. content: 'Hello World;
D. content: Hello+World;
Solution
Step 1: Understand string syntax in Sass
Strings must be enclosed in matching single or double quotes.
Concatenating 'Good' + 'Morning' results in 'GoodMorning' without space.
Step 2: Identify missing space issue
To get 'Good Morning', a space string ' ' must be added between variables.
Final Answer:
Missing space between words in concatenation -> Option B
Quick Check:
Concatenation needs spaces explicitly [OK]
Hint: Add ' ' string to insert spaces when joining words [OK]
Common Mistakes:
Assuming + adds spaces automatically
Not adding space string between variables
Confusing syntax errors with logic errors
5. You want to create a dynamic CSS class name by joining 'btn-' with a variable $color that can be 'red' or 'blue'. Which Sass code correctly creates the class name .btn-red or .btn-blue?
hard
A. .btn-{$color} { color: $color; }
B. .btn-" + $color + " { color: $color; }
C. .btn-#{$color} { color: $color; }
D. .btn-" #{$color} " { color: $color; }
Solution
Step 1: Understand string interpolation in selectors
Sass uses #{} to insert variable values inside strings or selectors.
Step 2: Check each option's syntax
.btn-#{$color} { color: $color; } uses .btn-#{$color} which correctly joins 'btn-' and variable. .btn-" + $color + " { color: $color; } uses + which is invalid in selectors. .btn-{$color} { color: $color; } misses #{} so variable won't be replaced. .btn-" #{$color} " { color: $color; } has invalid quotes placement.
Final Answer:
.btn-#{$color} { color: $color; } -> Option C
Quick Check:
Use #{} for variable interpolation in selectors [OK]
Hint: Use #{} to insert variables inside strings/selectors [OK]
Common Mistakes:
Trying to use + for selector concatenation
Forgetting #{} for interpolation
Incorrect quote placement around variables
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.