home
  • Blog
1.13
  • Getting Started
  • The Object Model
  • Templates
    • Handlebars Basics
    • The Application Template
    • Conditionals
    • Displaying a List of Items
    • Binding Element Attributes
    • Binding Element Class Names
    • Links
    • Actions
    • Input Helpers
    • Development Helpers
    • Rendering with Helpers
    • Writing Helpers
  • Routing
  • Components
  • Controllers
  • Models
  • Testing
  • Ember Inspector
  • Configuring Ember.js
  • Understanding Ember.js
  • Contributing to Ember.js
Old Guides - You are viewing the guides for Ember v1.13.0.
Go to v5.0.0

Binding Element Class Names

Edit pencil

An HTML element's class attribute can be bound like any other attribute:

<div class={{priority}}>
  Warning!
</div>

If the component's priority property is "p4", this template will emit the following HTML:

<div class="p4">
  Warning!
</div>

Conditional Values

If you want a class value based on a conditional property, use the Handlebars if helper:

<div class={{if isUrgent 'is-urgent'}}>
  Warning!
</div>

If isUrgent is true, this emits the following HTML:

<div class="is-urgent">
  Warning!
</div>

If isUrgent is false, no class name is added:

<div>
  Warning!
</div>

You can also specify a class name to add when the property is false:

<div class={{if isEnabled 'enabled' 'disabled'}}>
  Warning!
</div>

In this case, if the isEnabled property is true, the enabled class will be added. If the property is false, the class disabled will be added.

left arrow
Binding Element Attributes
Links
right arrow
On this page

  • Conditional Values
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2023 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue