Performance: Form validation styles
MEDIUM IMPACT
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 |