# Angular Templates and Styling Apply these rules when writing Angular templates, control flow, or component styles. ## Templates * Keep expressions short and readable. * Reading signals and `computed` values in templates is correct. Do not call other methods that compute or allocate from templates; use `computed` or a pure pipe instead. * Avoid complex conditions directly in markup. * Prefer derived state in TypeScript over repeated template expressions. * Use Angular control flow syntax such as `@if`, `@for` and `@switch` for new code. * In `@for`, track a stable unique key such as `track item.id`; use `$index` only for static lists that never reorder. For legacy `*ngFor`, supply `trackBy`. * Avoid deeply nested template structures. * Split large templates into focused components when it improves maintainability. * Avoid unnecessary DOM elements. * Use semantic HTML and native elements before custom implementations; see the accessibility section of the Angular security and accessibility rule. ## Styling * Keep styles scoped and predictable. * Avoid unnecessary global CSS. * Follow the project's styling strategy consistently. * Avoid excessive specificity. * Avoid `!important` unless there is a concrete reason. * Prefer reusable design tokens and shared styles over duplicated magic values. * Keep component styles focused on component concerns. * Avoid styling based on fragile DOM structure. * Do not mix multiple styling approaches without need.