0
0
SASSmarkup~8 mins

Accessibility utility generation in SASS - Performance & Optimization

Choose your learning style9 modes available
Performance: Accessibility utility generation
MEDIUM IMPACT
This affects page load speed and rendering by adding CSS utilities that improve accessibility without bloating the stylesheet.
Creating CSS utilities for accessibility features like focus outlines and screen reader text
SASS
%sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.sr-only {
  @extend %sr-only;
}

.element {
  @extend .sr-only;
}
Using placeholder selectors and extending them creates a single shared CSS rule, reducing stylesheet size and improving rendering efficiency.
📈 Performance GainSaves CSS bytes and reduces style recalculations, improving load and render speed.
Creating CSS utilities for accessibility features like focus outlines and screen reader text
SASS
@mixin sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.element {
  @include sr-only;
  @include sr-only;
  @include sr-only;
}
Repeatedly including the same mixin in multiple selectors duplicates CSS rules, increasing stylesheet size and causing redundant style recalculations.
📉 Performance CostAdds unnecessary CSS bytes and triggers multiple style recalculations during rendering.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Repeated mixin includes for accessibility utilitiesNo extra DOM nodesMultiple reflows if styles changeHigher paint cost due to redundant styles[X] Bad
Sass placeholder selectors with @extend for utilitiesNo extra DOM nodesSingle reflow on style changeLower paint cost with shared styles[OK] Good
Rendering Pipeline
Accessibility utilities generated via Sass flow through style calculation and layout stages. Efficient utilities minimize CSS size and reduce layout thrashing caused by large or redundant styles.
Style Calculation
Layout
Paint
⚠️ BottleneckStyle Calculation due to large or duplicated CSS rules
Core Web Vital Affected
CLS
This affects page load speed and rendering by adding CSS utilities that improve accessibility without bloating the stylesheet.
Optimization Tips
1Use Sass placeholders and @extend to share accessibility utility styles and avoid duplication.
2Keep accessibility utility CSS minimal to reduce stylesheet size and improve load speed.
3Test with DevTools Performance panel to detect style recalculations and layout shifts caused by CSS.
Performance Quiz - 3 Questions
Test your performance knowledge
What is a performance benefit of using Sass placeholder selectors with @extend for accessibility utilities?
AIt adds more CSS rules for better browser compatibility.
BIt reduces duplicated CSS rules, lowering stylesheet size and style recalculations.
CIt increases DOM nodes to improve accessibility.
DIt delays style calculation to after page load.
DevTools: Performance
How to check: Record a performance profile while loading the page and interacting with elements using accessibility utilities. Look for style recalculations and layout thrashing.
What to look for: Fewer style recalculations and shorter layout times indicate efficient accessibility utility CSS.