Performance: Button sizes
Button sizes affect the layout stability and rendering speed of interactive elements on the page.
<button class="btn btn-primary btn-sm">Small</button> <button class="btn btn-primary btn-lg">Large</button>
<button class="btn btn-primary" style="padding: 0.25rem 0.5rem; font-size: 0.75rem;">Small</button> <button class="btn btn-primary" style="padding: 1rem 2rem; font-size: 1.5rem;">Large</button>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline styles with varying sizes | Low | Multiple reflows per button | High due to layout shifts | [X] Bad |
| Bootstrap size classes (btn-sm, btn-lg) | Low | Single reflow on load | Low paint cost, stable layout | [OK] Good |
<button class="btn btn-primary ?">Click</button>btn-sm for small buttons and btn-lg for large buttons. The default button has no size class.btn-sm is the correct one to make a button smaller than default.<button class="btn btn-primary ?">Submit</button>btn-lg to make buttons larger than the default size.btn-lg. Other options like btn-large, btn-big, or btn-xl are not valid Bootstrap classes.<button class="btn btn-primary">Default</button> <button class="btn btn-primary btn-sm">Small</button>
btn btn-primary, so it is default size. The second button adds btn-sm, making it smaller.btn-sm class.<button class="btn btn-primary btn-small">Click Me</button>
btn-sm and btn-lg for sizes. btn-small is not valid.btn-primary and btn classes are correct and present. The button tag is properly closed.btn-success for green and btn-danger for red buttons.btn-lg. The 'Cancel' button should be small, so use btn-sm.btn-success btn-lg for 'Save' and btn-danger btn-sm for 'Cancel'. Other options swap colors or sizes incorrectly.Pass the test and this pattern moves unknown