You add Angular invalid styling by letting Angular's reactive or template-driven forms attach a validation class to the control, then writing CSS against that class—most commonly .ng-invalid, often combined with .ng-touched or .ng-dirty so errors appear only after the user has interacted. Angular 15 and later also register the native :invalid state, but the class-based approach works across versions and doesn't depend on browser pseudo-class behavior. If your styles "do nothing," the cause is almost always selector scope, ViewEncapsulation, or a condition that hasn't flipped to invalid yet.

The rest of this guide walks through the prerequisite setup, ordered steps for both forms styles, the exact selectors Angular applies and when, common failures, and a few worked patterns for border, message, and accessibility styling. Versions matter here: Angular reworked form control state around v15, so a few details below are version-sensitive and flagged as such.

What Angular actually adds to a control

When Angular compiles a form control, it attaches CSS classes that reflect its internal control status. For a template-driven field with ngModel and a required validator, an untouched empty input renders roughly like this:

Once the user types a valid value, Angular swaps ng-invalid for ng-valid. The core pair is:

ng-valid — the control currently passes all validators. ng-invalid — at least one validator fails.

Around that, Angular tracks interaction state:

ng-pristine until the user changes the value via the UI. ng-dirty after the value has been changed by the user. ng-untouched until the control receives a blur. ng-touched after the control has been blurred.

Angular also applies a ng-pending class while an asynchronous validator is unresolved, and a ng-submitted class on elements after a submit attempt. These exist so you can express "show errors only after the user has had a chance" without writing component logic.

One critical nuance: the validity classes describe validator state, not whether an error message is currently visible in your template. A pristine empty required field is ng-invalid from the first render, because the validator already considers the empty value a failure. That's why unstyled apps often flash red borders on page load. Combine with ng-touched, ng-dirty, or ng-submitted to defer the visual.

Version note: before Angular 15, the framework didn't manage the native :invalid pseudo-class on form controls. From v15 onward, Angular adds a matching native validity state (:valid/:invalid) alongside the classes. If you're on an older version, don't rely on :invalid—the class selectors are the portable path.

Prerequisites before you write any CSS

Four things need to be true for a class-based rule to match. Confirm them first; skipping this is the source of most "my CSS doesn't work" reports.

1: Forms module is imported. For template-driven forms, FormsModule must be in the feature module or standalone component's imports. For reactive forms, ReactiveFormsModule. Without it, ngModel or formControlName won't wire validators at all, and no validity classes appear. 2: The control is bound to a form directive. The classes are applied by NgModel, FormControlName, FormControlDirective, or NgControlStatus. A plain with no form binding gets none of them. 3: A validator is actually failing. A control with no validators is always ng-valid. required, minlength, pattern, a ValidatorFn, or a server-side async validator must be present and returning a failure. 4: Your selector can reach the element. Component styles are scoped by ViewEncapsulation (see the failures section), and the control must be inside the component whose stylesheet holds the rule.

If all four hold, the selector below will match and you can style freely.

Step-by-step: class-based invalid styling

This is the default approach and works in every Angular version that supports forms. It's ordered so each step is checkable before moving on.

Step 1 — bind the control. In a template-driven form, add name, [(ngModel)], and validators:

Export the directive to a template reference (#emailCtrl="ngModel") only if you need it for messages; the classes appear regardless. In a reactive form, the template is and the validators live in the component (new FormControl('', [Validators.required, Validators.email])).

Step 2 — confirm the class is present. Run the app and inspect the input in devtools. A failing validator shows ng-invalid in the class list. If it's absent, stop and fix prerequisites one through three—no selector will help yet.

Step 3 — write the base selector in the component stylesheet.

The element selector plus class keeps the rule from bleeding to unrelated elements that happen to be invalid.

Step 4 — gate the visual on interaction. Restrict to touched or dirty controls so users aren't greeted with errors before typing:

ng-touched fires after blur; ng-dirty fires after the first change. Pick one, or accept either with a comma. Gating on ng-touched alone means a user who types an invalid value but never leaves the field sees no error until they tab away—usually acceptable, occasionally not. Gating on ng-dirty shows feedback as they type, which suits less strict validation like password strength.

Step 5 — style the message visibility. If you show a sibling error paragraph, key it to the same state:

The template condition and the CSS gate should agree, or you'll get an unstyled message or a styled empty one. In newer standalone templates, @if (email.invalid && (email.touched || email.dirty)) { ... } replaces *ngIf.

Step 6 — verify success. In devtools, blur the empty field: ng-touched appears and the border color applies. Type a valid email: ng-invalid is replaced by ng-valid and the border resets. If the border applies but never resets, a second rule (often a more specific selector or a later stylesheet) is overriding it—check the computed styles panel for the winning declaration.

Stop condition: if classes flip correctly but the visual never changes, the problem is selector scope or specificity, not forms. Toggle the rule off in devtools to isolate. If classes never flip at all, revisit module imports and validator configuration before touching CSS.

Step-by-step: using the native :invalid state

Version-gated to Angular 15 and later. This is shorter but interacts with browser default styling and doesn't expose touched/dirty, so you typically pair it with :user-invalid where supported.

Step 1 — confirm the version. Check package.json for a @angular/core version of 15 or higher. On older releases, use the class method above.

Step 2 — write the pseudo-class rule.

Because Angular now ties native validity to the control, a failing validator yields :invalid. Be aware this also applies before interaction, because :invalid matches the prerender state just like the class does.

Step 3 — defer with :user-invalid if the browser supports it. input:user-invalid { border-color: #c62828; } fires only after user interaction, giving you the touched-like gating for free. Support varies; treat it as a progressive enhancement layered over a class-based fallback.

Step 4 — suppress native browser UI. Browsers may show their own validation bubbles on submit. form novalidate or novalidate on the form stops the browser's own tooltip and lets your styling own the feedback.

Step 5 — verify. Blur an invalid field and confirm the border appears; enter a valid value and confirm it clears. If :invalid matches on load but you wanted deferred feedback, add :user-invalid or switch to the class method.

For most teams I'd recommend the class approach as the primary baseline and layer :user-invalid on top only if browser targets allow it. The class selectors are stable across Angular versions and give you touched/dirty control directly.

The full state table Angular maps to classes

Understanding which class fires when prevents most surprises. The table below summarizes control state to class mapping; it works through each interaction sequence rather than restating prose.

User action ng-pristine/ng-dirty ng-untouched/ng-touched ng-valid/ng-invalid
Initial render pristine untouched reflects validators immediately
User types a value dirty untouched until blur recomputes on each value change
Field loses focus unchanged touched unchanged by blur
Value reset programmatically pristine untouched recomputes
Async validator running unchanged unchanged ng-pending replaces valid/invalid

Two implications worth internalizing. First, ng-invalid can be true while ng-pristine is also true—an empty required field on load. Second, programmatic resets (via reset() or reassigning the control) return the control to pristine and untouched, which clears your gated error styling even though the value may still be invalid. If you want errors to persist after reset until the user re-engages, you'll need component logic rather than CSS alone.

Also note that ng-submitted applies to the , not controls, after a submit attempt. You can use it to reveal errors on all controls at once: form.ng-submitted input.ng-invalid { border-color: #c62828; }. This is the pattern for "validate everything on submit." A CSS descendant selector handles the whole form without per-field logic.

Patterns for borders, messages, and accessibility

A single red border is rarely enough; here are three reusable patterns, each fully specified.

Border and focus ring. Style invalid focus explicitly so the red border and the focus outline don't fight:

Keep invalid and focus states distinguishable—don't rely on color alone. A thicker border or an icon next to the message helps users who can't perceive the hue difference.

Colored, non-flashing error message. Reserve space for the message so layout doesn't jump:

Render the element always and toggle text, or use *ngIf and accept the height shift—reserving space is smoother if the message area is prominent.

Accessible invalid state. CSS alone doesn't tell assistive technology that a field is invalid. Bind the ARIA attribute to the same condition you use for the message:

Angular sets aria-invalid through the attribute binding; the aria-describedby should point at the message element's ID when it's visible. This matters more than the border color: a screen reader user needs the error announced, not just colored.

Unified state class. For complex forms, you can collapse the composite into one class in the template rather than writing multi-class selectors everywhere:

Then CSS is simply .is-error { border-color: #c62828; }. This centralizes the gate in one expression per field, which is easy to audit in code review.

When the styling doesn't apply

The classes are working if devtools shows ng-invalid and you toggled the rule manually with no effect. Work through these in order; each is reversible.

ViewEncapsulation scoping. A component with the default Emulated encapsulation rewrites selectors with an attribute like [_ngcontent-xyz], so a rule in one component won't style an input rendered by a child component unless ::ng-deep (discouraged, deprecated) or a global stylesheet is used. Put form styling in styles.css/styles.scss globally, or in the component that actually renders the input. For nested components, prefer a shared global class (.app-field.is-invalid) over reaching through encapsulation boundaries. Standalone components and their host styles follow the same scoping rules, so a rule in the parent's styles won't match a child's input.

Specificity conflicts. A rule like input { border-color: #ccc; } in a later-loaded stylesheet can win over input.ng-invalid { ... } only if the invalid rule is less specific—it isn't, since two class/type combos beat one. But inline style attributes or framework resets (for example, a UI library's boxed input styles) can override. Check the "computed" tab to see which selector wins, then match or exceed that specificity rather than piling on classes.

The control isn't actually invalid. A minlength validator on an empty optional field passes, so the control stays ng-valid. Confirm your validator's logic—especially custom ValidatorFns that return null on success and an error object on failure; a refactored validator returning a falsy object or wrong shape silently passes. Async validators leave the control ng-pending, not ng-invalid, so a rule keyed only to ng-invalid won't fire while the request is in flight; add ng-pending styling separately if you want a spinner state.

Template reference only updates on touched. Using #email="ngModel" with email.invalid for messages is fine, but relying on email.touched in CSS isn't possible—the reference doesn't affect classes. Keep the CSS gate and template expression identical, and remember the reference reports validated state about the preceding render, not live keystrokes, in some change-detection edge cases.

Multiple classes and order. A control can be both ng-invalid and ng-pending. If your selectors don't account for the pending state, the shared ng-invalid rule may apply during async checks, causing a red flash. Add a guard: input.ng-invalid.ng-touched:not(.ng-pending).

Worked example: one field through the full lifecycle

Consider an email field in a template-driven form with required and email validators. Here's the class evolution and the CSS behavior at each step.

1: Page loads, field empty. Classes: ng-pristine ng-untouched ng-invalid. The input.ng-invalid base rule matches, but the gated rule (.ng-touched) does not—no red border. This is the desired neutral state. 2: User focuses the field. No class change on focus. 3: User types "a". Classes: ng-dirty ng-untouched ng-invalid (the email validator fails). The ng-dirty gate now applies, so the border turns red immediately. Whether this is wanted depends on your policy—email errors as the user types can feel noisy, so many teams switch to ng-touched for that field. 4: User blurs. Classes: ng-dirty ng-touched ng-invalid. Both gates agree; the error message shows and is announced via aria-invalid. 5: User types a valid address. Classes: ng-dirty ng-touched ng-valid. Both the border rule and the message conditional drop out; the field returns to neutral styling. 6: User submits the empty form after clearing. The form gets ng-submitted; the field is ng-invalid and now ng-pristine if it was reset. A form.ng-submitted input.ng-invalid rule reveals the error even without touch—the "validate on submit" path.

Consulting an external timer or counting keystrokes isn't required; the class state is the single source of truth and the CSS reads it directly.

Limits and edge cases to plan for

CSS can only react to state Angular exposes. A few boundary cases fall outside what selectors can express:

Server-side errors. A 409 or "email already registered" response arrives without a client validator failure, so the control is ng-valid. Set an error on the control programmatically (control.setErrors({ taken: true }) immediately after the response, and clear it on the next value change), then style .ng-invalid as before. Server errors need an ngModelChange handler to clear them, or the field stays red after correction. Group-level validation. A FormGroup validator marks the group invalid, and the group's classes appear on the form element, not individual inputs. Reveal the group error with form.ng-invalid.ng-touched and handle messaging in the template. Dynamic validators. When validators are added or removed at runtime (setValidators + updateValueAndValidity), the classes update only after recalculation. Call updateValueAndValidity() following the change, or the field's class list reflects stale state. Async validators and cancellation. Each keystroke can cancel an in-flight async check. ng-pending will flicker; don't drive animation or layout from it without a guard. Accessibility is not CSS. ARIA attributes and message association carry the error to assistive tech; visual color is a secondary cue. A red border with no aria-invalid and no described message passes a screenshot review and fails real users.

Finally, since form UX conventions differ across teams, treat the ng-touched versus ng-dirty gate as a product decision, not a technical default, and document it in one place so the CSS, the template, and the ARIA bindings stay in lockstep.