C&C Docs
Log in
Templates

Text — x-text

x-text sets an element's text content from an expression — escaped, so it is always safe. It is the only way to put an expression in text: put it on the element that owns the text, or on a <span> where the expression sits inside a sentence. For an attribute, bind it with :attr.

x-text on the element
<p class="text-lg" x-data="{ name: 'Ada Lovelace' }" x-text="'Hello, ' + name"></p>
Result

Hello, Ada Lovelace

A span inside a sentence
<div x-data="{ user: 'ada', count: 3 }">
  <p class="text-lg">
    <span class="" x-text="user"></span>
    has
    <span class="tabular-nums" x-text="count"></span>
    unread messages
  </p>
</div>
Result

ada has 3 unread messages