Templating and styling with Alpine.js

decorating our HTML with style directives

// updated 2025-09-26 13:36

For an Alpine.js app, we can easily and quickly add ad hoc styling to our templates:

  • use the x-bind:style or, in shorthand, the :style directive

For those familiar with React, the CSS style properties will use the similar style object "camelCase" property name convention: instead of font-size, we must use the fontSize instead!

Also, notice how we can use the data in the x-data directive's value by referring to any of its property names as a value in an x-text directive attribute!

⬅️ older (in textbook-alpinejs)
🏔️ Searching within lists with Alpine.js
newer (in textbook-alpinejs) ➡️
Rendering lists in Alpine.js 🏔️
⬅️ older (in code)
🏔️ Searching within lists with Alpine.js
newer (in code) ➡️
Shorthand cheatsheet for Alpine.js 🏔️
⬅️ older (posts)
🏔️ Searching within lists with Alpine.js
newer (posts) ➡️
Shorthand cheatsheet for Alpine.js 🏔️