Performance: Close button component
This affects page load speed and interaction responsiveness by how the close button is implemented and styled.
<button type="button" class="btn-close" aria-label="Close" onclick="closeModal()"></button>
<div onclick="closeModal()" style="cursor:pointer; font-size: 24px;">×</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| <div> with inline styles and onclick | Minimal but non-semantic | Triggers reflow on style changes | Moderate due to inline styles | [X] Bad |
| <button> with Bootstrap btn-close class | Minimal and semantic | Single reflow on interaction | Low due to optimized CSS | [OK] Good |
btn-close component?btn-closebtn-close class is designed to create a small button with an X icon.button element with class btn-close.aria-label="Close" for screen readers.<div class="alert alert-warning alert-dismissible fade show" role="alert"> Warning! Something went wrong. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div>
alert alert-warning alert-dismissible fade show classes create a yellow warning alert that can be dismissed.btn-close button with data-bs-dismiss="alert" will show a small X that closes the alert on click.<button class="btn-close" aria-label="Close">X</button>
button with class btn-close and data-bs-dismiss="modal" to close the modal.aria-label="Close" so screen readers understand its purpose.Pass the test and this pattern moves unknown