Building with AI?
llms.txt
Error & Valid States
Style elements based on error and valid states using the if-error / then-* / else-* pattern.
Live Demo
Submit the form to see error and valid states in action.
Source Code
Key Concepts
The if-error / then / else Pattern
Error state directives follow a conditional pattern:
if-error="field"- Targets a specific fieldthen-*- Applied when there's an errorelse-*- Applied when field is valid (after submit)
Error State (then-*)
then-show- Show element on errorthen-show-text- Show and inject error messagethen-hide- Hide element on errorthen-class="..."- Apply classes on errorthen-text="..."- Set specific text on errorthen-style="..."- Apply inline styles on error
Valid State (else-*)
else-hide- Hide element when validelse-class="..."- Apply classes when validelse-text="..."- Set text when validelse-style="..."- Apply inline styles when valid
Input Convenience Directives
Apply directly to input elements:
error-class="..."- Classes on errorerror-style="..."- Styles on errorvalid-class="..."- Classes when validvalid-style="..."- Styles when valid
Important: Elements without else-* directives stay in their base state when valid. Use else-hide to explicitly hide on valid.