Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Accessibility Utility Generation with Sass
📖 Scenario: You are building a small Sass utility to help web developers quickly add accessibility features to their HTML elements. These utilities will include classes to visually hide content but keep it accessible to screen readers, and classes to manage focus outlines for keyboard navigation.
🎯 Goal: Create a Sass file that defines accessibility utility classes using variables and loops. The utilities should include a visually hidden class and a focus-visible outline class. This will help developers improve accessibility easily by adding these classes to their HTML elements.
📋 What You'll Learn
Create a Sass map variable called $accessibility-utilities with two entries: visually-hidden and focus-outline.
Add a configuration variable $focus-outline-color set to #005fcc.
Use a Sass @each loop to generate CSS classes for each utility in $accessibility-utilities.
Complete the CSS rules for .visually-hidden and .focus-outline classes using the map values and configuration variable.
💡 Why This Matters
🌍 Real World
Accessibility utilities help developers quickly add important features for screen reader users and keyboard navigation without writing repetitive CSS.
💼 Career
Knowing how to write reusable Sass utilities and manage accessibility is valuable for front-end developers working on inclusive websites.
Progress0 / 4 steps
1
Create the accessibility utilities map
Create a Sass map variable called $accessibility-utilities with these exact entries: visually-hidden and focus-outline. The value for visually-hidden should be a nested map with keys position set to absolute, width set to 1px, height set to 1px, padding set to 0, margin set to -1px, overflow set to hidden, clip set to rect(0, 0, 0, 0), white-space set to nowrap, and border set to 0. The value for focus-outline should be a nested map with keys outline-style set to solid, outline-width set to 2px, and outline-offset set to 2px.
SASS
Hint
Use a Sass map with nested maps for each utility. Follow the exact keys and values given.
2
Add the focus outline color variable
Add a Sass variable called $focus-outline-color and set it to the exact color value #005fcc.
SASS
Hint
Define a simple Sass variable with the exact name and color value.
3
Generate CSS classes with @each loop
Use a Sass @each loop with variables $name and $properties to iterate over $accessibility-utilities. Inside the loop, create a CSS class named .#{$name} and set its CSS properties using another @each loop over $properties with variables $prop and $value. Assign each property $prop the value $value.
SASS
Hint
Use nested @each loops: outer for utilities, inner for properties.
4
Add the focus color to the focus-outline class
Add a CSS property outline-color with the value $focus-outline-color inside the .focus-outline class only. Do this by adding an @if condition inside the @each loop that checks if $name equals focus-outline. If true, add outline-color: $focus-outline-color; inside the class.
SASS
Hint
Use an @if condition inside the loop to add the outline-color only for the focus-outline class.
Practice
(1/5)
1. What is the main purpose of accessibility utilities in SASS?
easy
A. To add colorful backgrounds to web pages
B. To make websites easier to use for everyone, including people with disabilities
C. To speed up website loading times
D. To create animations for buttons
Solution
Step 1: Understand accessibility utilities
Accessibility utilities are styles or code that help users with disabilities navigate and use websites better.
Step 2: Identify the main goal
The main goal is to improve usability for everyone, especially those with disabilities, not visual decoration or speed.
Final Answer:
To make websites easier to use for everyone, including people with disabilities -> Option B
Quick Check:
Accessibility = usability for all [OK]
Hint: Accessibility utilities improve usability for all users [OK]
Common Mistakes:
Confusing accessibility with visual design
Thinking accessibility speeds up loading
Assuming accessibility is only for animations
2. Which SASS syntax correctly defines a mixin for hiding content visually but keeping it accessible to screen readers?
Each property must end with a semicolon to separate declarations.
Step 2: Locate missing semicolon
The line 'outline: 2px solid $color' lacks a semicolon at the end, causing syntax error.
Final Answer:
Missing semicolon after outline property -> Option A
Quick Check:
Missing semicolon = syntax error [OK]
Hint: Always end SASS properties with semicolons [OK]
Common Mistakes:
Forgetting semicolons between properties
Thinking $color needs quotes
Confusing property names
5. You want to create a reusable SASS utility mixin that generates both a focus outline and a screen-reader-only style. Which of the following is the best combined mixin code?