Templating ========== Alpine offers a handful of useful directives for manipulating the DOM on a web page. Let's cover a few of the basic templating directives here, but be sure to look through the available directives in the sidebar for an exhaustive list. [Text content](#text-content) ----------------------------- Alpine makes it easy to control the text content of an element with the `x-text` directive.

**Start Here** Now, Alpine will set the text content of the `

` with the value of `title` ("Start Here"). When `title` changes, so will the contents of `

`. Like all directives in Alpine, you can use any JavaScript expression you like. For example: 3 The `` will now contain the sum of "1" and "2". [→ Read more about `x-text`](/directives/text) [Toggling elements](#toggling-elements) --------------------------------------- Toggling elements is a common need in web pages and applications. Dropdowns, modals, dialogues, "show-more"s, etc... are all good examples. Alpine offers the `x-show` and `x-if` directives for toggling elements on a page. ### [`x-show`](#x-show) Here's a simple toggle component using `x-show`.
 
Content...
Content...
Expand Content... Now the entire `
` containing the contents will be shown and hidden based on the value of `open`. Under the hood, Alpine adds the CSS property `display: none;` to the element when it should be hidden. [→ Read more about `x-show`](/directives/show) This works well for most cases, but sometimes you may want to completely add and remove the element from the DOM entirely. This is what `x-if` is for. ### [`x-if`](#x-if) Here is the same toggle from before, but this time using `x-if` instead of `x-show`.
 
Expand Notice that `x-if` must be declared on a `