HTML & CSS interview questions
Show answer
A
<button>is focusable, works with Enter and Space, is announced as a button by screen readers and can submit forms. A<div>needstabindex, a role, keyboard handlers and focus styles to come close — and is usually still incomplete. Use links for navigation and buttons for actions.Show answer
When rules conflict, the more specific selector wins: inline styles, then IDs, then classes/attributes/pseudo-classes, then elements. Equal specificity falls back to source order.
!importantoverrides normal rules and makes code hard to maintain. Cascade layers (@layer) let you control precedence between groups of styles explicitly.