QA
Beginner LevelHTML & Semantic Web

Why must you specify type="button" on non-submitting form buttons?

❓ Interview Prompt: Explain button type attributes (submit, reset, button) and default form submit behaviors.

Inside a '<form>', an un-typed '<button>' defaults to 'type="submit"'!

The Problem:

If a button inside a form triggers a JavaScript modal or counter, omitting 'type="button"' will cause the browser to submit the form and refresh the page unexpectedly!

Rule:

Always explicitly declare 'type="button"' for non-submitting action buttons inside forms.

Code Implementation Example

html
<form>
  <!-- Submits form by default -->
  <button type="submit">Save Settings</button>

  <!-- Safe: Does NOT submit form -->
  <button type="button" onclick="resetDraft()">Reset Draft</button>
</form>
💡Explicitly specifying type="button" to prevent accidental form submission.
🎯 Interview Key Takeaway

Always set type="button" on non-submitting buttons inside forms to prevent unexpected page reloads.

#button#type attribute#Forms#Beginner
Back to all HTML & Semantic Web Questions→

More HTML & Semantic Web Interview Questions

Beginner LevelHTML & Semantic Web

What is Semantic HTML and why is it essential for modern web applications?

Beginner LevelHTML & Semantic Web

What is <!DOCTYPE html> and what happens if it is omitted?

Beginner LevelHTML & Semantic Web

What is the difference between inline and block-level HTML elements?