Performance: Form validation styles
Form validation styles affect the rendering speed and visual stability during user input and form submission.
<input id="email" type="email" class="is-invalid" /> <style> .is-invalid { border-color: #dc3545; background-color: #f8d7da; } </style>
<input id="email" type="email" /> <script> document.getElementById('email').style.borderColor = 'red'; document.getElementById('email').style.backgroundColor = '#ffe6e6'; </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline style changes per property | Multiple style changes on same element | 2 reflows per input | High paint cost due to multiple repaints | [X] Bad |
| Single CSS class toggle | One class added/removed | 1 reflow per input | Lower paint cost with combined style changes | [OK] Good |
is-valid to mark inputs as valid and is-invalid for invalid inputs.is-valid visually marks the input as valid with green borders and icons.invalid-feedback class inside a div to show invalid messages.<div class="invalid-feedback">Message</div> placed after the input.<input type="text" class="form-control is-invalid" /> <div class="invalid-feedback">Please enter a valid name.</div>
is-invalid which applies a red border and error icon.invalid-feedback div shows the error message below the input in red text.<input type="email" class="form-control" id="email" required> <div class="valid-feedback">Looks good!</div> <div class="invalid-feedback">Please enter a valid email.</div>
is-valid or is-invalid classes, so no visual feedback appears.required is valid HTML5 attribute.is-valid on input to show green border and success icon.div with class valid-feedback placed immediately after the input.Pass the test and this pattern moves unknown