HTML is where mature JavaScript patterns graduate to, removing the need for scripting for common, well-established user interactions. Having a button switch some state on click is a common pattern that needs to move into a declarative HTML-only setup.
Button-type buttons (<button type="button"></button>
) have no inherent behavior. Currently, they require scripting to do anything. A common behavior added is to switch some state:
- Menu button toggles the state of a menu between "open" and "closed"
- Toggle button switches a site setting, e.g. between "dark mode," "light mode," and "match OS"/"auto"
- Tab/accordion button switches the state of the tabset or accordion to one particular section (alternatively, it sets the state for the designated section to "active/open/visible" and the states for all other sections to "inactive/closed/hidden")