Alpine JS x-text and x-html binding Example

May 12, 2021 . Admin

Hi Dev,

Today, I will discuss about that how to work x-text and x-html in alpine JS.

Using the x-html directive, we can integrate some dynamic HTML inside any element.


works similarly to x-text, but instead of setting the innerText, it sets the value of the innerHTML of an element.

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

Now, let’s started with bellow example, I will give you simple x-text and x-html using alpine js you can see on below example code. you can simply copy and check that.

You can visually perceive from the code bellow that we inject a dynamic listed item inside of the div element.

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


<div x-data="{ 
		name: 'Paresh',
		body: '<ul><li>PHP</li><li>Laravel</li><li>Vue</li></ul>' 
	<div x-text="name"></div>
	<div x-html="body"></div>


I Hope It Will Help You..

#Alpine JS