CORE ANGULAR • LESSON 5 OF 23

Class and Style Binding

What you will learn

Express visual states through classes, style properties, and accessible text.

  • Use [class.name] for one conditional class and [style.property] for one calculated property. A class binding keeps shared design rules in CSS.
  • A visual state should have a text or semantic equivalent. Color alone is not enough to communicate pass/fail, positive/negative, or selection.
  • Angular also supports class and style map bindings. Return stable data when possible rather than creating complex objects during every template evaluation.
  • CSS controls layout. Use template bindings for states that truly come from component data.

How it works

1Data defines state
2Binding selects class
3CSS applies presentation
4Text preserves meaning

Expected result

Scores 81 and 93 receive the high-score style; 42 and 67 remain standard. Every row has a readable text result.

Common mistakes

Do not place every reusable CSS declaration in an inline style binding. Do not communicate meaning only through green and red colors.

Read the official Angular guide →