0
0
SASSmarkup~10 mins

Combining & with pseudo-classes in SASS - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Combining & with pseudo-classes
Read .button selector
Create .button node
Parse & in nested selector
Combine & with :hover
Create .button:hover rule
Apply styles on hover
Render visual changes on hover
The browser reads the base selector .button, then combines it with the pseudo-class :hover using the & symbol in Sass. This creates a new CSS rule .button:hover that applies styles when the user hovers over the button.
Render Steps - 3 Steps
Code Added:<button class="button">Click me</button>
Before
[ ]
(empty page)
After
[button: 'Click me']
The button element appears on the page with default browser styles.
🔧 Browser Action:Creates DOM node and applies default styles
Code Sample
A button with a light blue background that changes to a deeper blue when hovered over.
SASS
<button class="button">Click me</button>
SASS
.button {
  background-color: lightblue;
  padding: 1rem 2rem;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  &:hover {
    background-color: deepskyblue;
  }
}
Render Quiz - 3 Questions
Test your understanding
After applying step 3, what happens when you hover the button?
AThe button background changes to deep sky blue
BThe button text changes color
CNothing changes visually
DThe button disappears
Common Confusions - 2 Topics
Why doesn't &:hover work if I forget the & symbol?
Without &, the nested :hover becomes a separate selector, not combined with the parent. So styles won't apply on hovering the parent element.
💡 Always use & to combine parent selector with pseudo-classes in nested Sass.
Why does the hover style not apply on child elements inside the button?
The :hover pseudo-class applies to the element itself, not its children. So only the button background changes, not inner text or icons unless styled separately.
💡 Style child elements explicitly if you want them to change on hover.
Property Reference
PropertyValue AppliedSelector EffectVisual EffectCommon Use
&Used in nested selectorsRepresents parent selectorCombines with pseudo-classes or elementsSimplifies writing complex selectors
:hoverPseudo-classMatches element on mouse hoverChanges style on mouse overInteractive feedback on buttons/links
background-colorcolor valueApplies to elementChanges background colorVisual styling of elements
paddinglength valuesApplies inside element borderAdds space inside elementImproves clickable area and spacing
border-radiuslength or %Applies to element cornersRounds corners visuallySoftens element edges
Concept Snapshot
In Sass, & represents the parent selector. Use & combined with pseudo-classes like :hover to style states. Example: .button { &:hover { ... } } compiles to .button:hover { ... }. This creates interactive styles that apply on user actions. Always include & in nested pseudo-class selectors to combine properly.