0Pricing
Vue Academy · Lesson

Attribute and Class Bindings

Bind attributes, classes, and styles dynamically.

Binding Classes and Styles

A common need is changing an element class or style based on state.

Vue special-cases :class and :style so you can pass objects and arrays, not just strings.

:class Object Syntax

Pass an object to :class. Keys are class names; truthy values include them.

<div :class="{ active: isActive, disabled: isDisabled }">
  Status box
</div>

<!-- if isActive is true, the "active"
     class is applied -->

All lessons in this course

  1. Interpolation and Directives
  2. Conditionals and Loops
  3. Attribute and Class Bindings
← Back to Vue Academy