#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
3 min read
Question 21 of 37easy

What is the difference between v-if and v-show?

Conditional rendering strategies.

What You'll Learn

  • v-if behavior
  • v-show behavior
  • When to use each

v-if

Conditionally renders element. Removes from DOM when false.

code.txtVUE
<template>
  <div v-if="isVisible">
    This is removed from DOM when false
  </div>
</template>

v-show

Always renders, toggles display CSS property.

code.txtVUE
<template>
  <div v-show="isVisible">
    This stays in DOM, just hidden
  </div>
</template>

Comparison

Featurev-ifv-show
DOMAdds/removesAlways present
Initial costLowerHigher
Toggle costHigherLower
With v-elseYesNo
LazyYesNo

When to Use

code.txtVUE
<!-- v-if: Rarely toggled, heavy content -->
<HeavyComponent v-if="showOnce" />

<!-- v-show: Frequently toggled -->
<Dropdown v-show="isOpen" />