0
0
SASSmarkup~30 mins

Accessibility utility generation in SASS - Mini Project: Build & Apply

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a hint?

Use an @if condition inside the loop to add the outline-color only for the focus-outline class.