Alpine JS Add Remove Class Example

May 13, 2021 . Admin

Hi Dev,

Today, I will learn you how to use add and remove class in Alpine JS. We will show example of hide and show on click event in Alpine JS, you can easliy use in your laravel project.

In this example bellow toggle list categories and we apply attribute :class

. Here, I will give you full example for simply add and remove class in alpine JS as bellow.

you can also use this example in your php and laravel alpine JS project.

I will give you simple toggle event example using alpine js you can see on below example code. you can simply copy and check that.

<!DOCTYPE html>
	<script src="" defer></script>
	<style type="text/css">
			padding: 50px;
			background-color: #f7fcff;
			display: block;
			display: none;


<div x-data="{ open: false }">

  <h1>Alpine js Add Remove Class Example -</h1>

  <button @click="open = !open">Toggle List Categories</button>
  <ul :class="{'open-class' : open, 'hidden-class' : !open}">


I Hope It Will Help You..

#Alpine JS