0
0
Vueframework~10 mins

CSS transition classes in Vue - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - CSS transition classes
Element enters DOM
Add v-enter class
Add v-enter-active class
Trigger browser reflow
Remove v-enter class
Add v-enter-to class
Transition runs
Remove v-enter-to and v-enter-active classes
Element fully entered
When an element appears, Vue adds special classes step-by-step to trigger CSS transitions smoothly.
Execution Sample
Vue
<template>
  <transition name="fade">
    <div v-if="show">Hello</div>
  </transition>
</template>
This code shows a div with fade transition when 'show' changes.
Execution Table
StepActionClasses Added/RemovedBrowser ReflowTransition State
1Element insertedAdd v-enterNoStart entering
2Add v-enter-activeAdd v-enter-activeNoPrepare transition
3Trigger reflowNo changeYesForce style recalculation
4Remove v-enterRemove v-enterNoStart transition to end state
5Add v-enter-toAdd v-enter-toNoTransition running
6Transition endsRemove v-enter-to and v-enter-activeNoEntered complete
7Element fully visibleNo classesNoStable state
💡 Transition finished, all temporary classes removed, element fully visible.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 4After Step 5After Step 6Final
elementClasses[]["v-enter"]["v-enter", "v-enter-active"]["v-enter-active"]["v-enter-active", "v-enter-to"][][]
transitionState"none""start entering""prepare transition""start transition to end state""transition running""entered complete""stable"
Key Moments - 3 Insights
Why does Vue add both v-enter and v-enter-active classes at first?
Vue adds v-enter to set the start style and v-enter-active to define the transition properties. This pairing allows the browser to know what to animate. See execution_table steps 1 and 2.
What is the purpose of triggering a browser reflow in step 3?
Triggering reflow forces the browser to apply the initial styles before moving to the final styles. This ensures the transition runs smoothly. Refer to execution_table step 3.
When are the transition classes removed and why?
After the transition ends, Vue removes v-enter-to and v-enter-active classes to clean up and leave the element in its final visible state. See execution_table step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, which classes are present right after the browser reflow?
A["v-enter", "v-enter-active"]
B["v-enter-active"]
C["v-enter-to"]
D[]
💡 Hint
Check the Classes Added/Removed column at Step 2 and Step 3 in execution_table.
At which step does the transition actually start running?
AStep 4
BStep 5
CStep 2
DStep 6
💡 Hint
Look at the Transition State column in execution_table to find when 'transition running' occurs.
If the browser reflow (Step 3) was skipped, what would likely happen?
ATransition would run normally
BClasses would not be added
CTransition might not run or jump abruptly
DElement would not appear
💡 Hint
Consider the importance of reflow in execution_table Step 3 and key_moments explanation.
Concept Snapshot
Vue CSS transition classes flow:
- Add v-enter and v-enter-active on element insert
- Trigger browser reflow to apply start styles
- Remove v-enter, add v-enter-to to start transition
- On transition end, remove v-enter-to and v-enter-active
- Element stays visible without transition classes
This sequence ensures smooth CSS animations on enter.
Full Transcript
When Vue shows an element with a transition, it adds special CSS classes in a specific order. First, it adds v-enter and v-enter-active to set the start styles and transition properties. Then it triggers a browser reflow to make sure styles are applied. After that, it removes v-enter and adds v-enter-to to start the transition to the final style. When the transition finishes, Vue removes the temporary classes, leaving the element fully visible. This step-by-step class management makes the CSS transition smooth and visually appealing.