🎉  The Alpine Day 2021 videos are out! Watch Now


x-if is used for toggling elements on the page, similarly to x-show, however it completely adds and removes the element it's applied to rather than just changing its CSS display property to "hidden".

Because of this difference in behavior, x-if should not be applied directly to the element, but instead to a <template> tag that encloses the element. This way, Alpine can keep a record of the element once it's removed from the page.

<template x-if="open">

Unlike x-show, x-if, does NOT support transitioning toggles with x-transition.