Performance: Fieldsets for form layout
MEDIUM IMPACT
Using fieldsets affects the form's HTML structure and rendering speed by grouping related fields, impacting layout stability and paint time.
<form>
<fieldset>
<legend>Contact Info</legend>
<label for="name">Name</label>
<input id="name" type="text" name="name">
<label for="email">Email</label>
<input id="email" type="email" name="email">
</fieldset>
<fieldset>
<legend>Message</legend>
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
</fieldset>
</form><form>
<div>
<label>Name</label>
<input type="text" name="name">
</div>
<div>
<label>Email</label>
<input type="email" name="email">
</div>
<div>
<label>Message</label>
<textarea name="message"></textarea>
</div>
</form>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using divs for grouping | More nodes, no semantic grouping | Multiple reflows on style changes | Higher paint cost due to layout shifts | [X] Bad |
| Using fieldsets with legends | Fewer nodes, semantic grouping | Single reflow on style changes | Lower paint cost with stable layout | [OK] Good |