# Angular Templates and Styling Apply these rules when writing Angular templates, control flow, or component styles. Load the UI/UX rules for visual design. ## Templates * Keep template expressions short. Reading signals and `computed` values is correct; do not call other methods that compute or allocate from templates, and move complex conditions into `computed` state or a pure pipe. * Use built-in control flow (`@if`, `@for`, `@switch`) in 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`. * Split large or deeply nested templates into focused components, and avoid unnecessary DOM elements. * Use semantic HTML and native elements before custom implementations; see the accessibility section of the Angular security and accessibility rule. * Keep user-facing text translatable with the project's i18n approach, such as `i18n` attributes and `$localize`, and format dates, numbers, and currencies with locale-aware pipes instead of hand-built strings. ## Styling * Keep styles scoped to the component and follow the project's styling strategy; avoid unnecessary global CSS and mixing styling approaches. * Prefer design tokens and shared styles over magic values. Avoid excessive specificity, `!important`, and selectors that depend on fragile DOM structure.