input type="button"

An <input type="button"> creates a general-purpose button. It does not submit its form; JavaScript or another handler must provide the action.

What you will learn

Basic example

<input type="button" value="Show details" id="show-details">
<script>
  document.querySelector('#show-details').addEventListener('click', () => {
    document.querySelector('#details').hidden = false;
  });
</script>

The value attribute supplies the visible label. Give the control a useful label that describes the action rather than relying on a vague word such as “Click.”

Choose the right control

Do not use a non-button element with a click handler when a native button can do the job. Native controls provide expected keyboard and focus behavior.

Related pages