html-button-type-submit-gotcha

Enforce explicit button types to prevent unintended form submissions in HTML and React.

1|Updated Jan 23, 2026
One-click install
npx skills add https://github.com/Hankanman/claude-config --skill html-button-type-submit-gotcha
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: html-button-type-submit-gotcha
Source: https://github.com/Hankanman/claude-config/tree/main/config/skills/html-button-type-submit-gotcha
Command: npx skills add https://github.com/Hankanman/claude-config --skill html-button-type-submit-gotcha

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Buttons inside forms without an explicit type default to submit, causing unintended submissions when users intend actions like close, cancel, or toggling UI. This Skill addresses that gotcha by guiding developers to enforce explicit type attributes on all UI buttons.

Core Features & Use Cases

  • Enforces explicit type="button" for non-submitting UI controls (Close, Cancel, Dismiss) inside forms.
  • Documents common patterns across HTML, React components, and other frameworks to prevent accidental form submissions.
  • Provides practical examples showing how to update components to avoid submit behavior during UI interactions.

Quick Start

Review all buttons inside forms and explicitly set type="button" for UI buttons (e.g., Close, Cancel) and type="submit" only for actual submit actions. Update components in HTML and React to prevent default submission behavior.

Frequently Asked Questions about html-button-type-submit-gotcha

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my React form submit when clicking the cancel or close button?

Your form submits because buttons inside a form element default to type="submit". You must explicitly set type="button" on non-submitting UI controls like cancel or close buttons to prevent unintended form submissions.

How do I prevent unintended form submissions in React components?

To prevent unintended form submissions, review all buttons inside your forms and explicitly set type="button" for UI controls like close, cancel, or dismiss. Reserve type="submit" only for actual submit actions in your React components.

What is the default button type inside an HTML form?

The default button type inside an HTML form is submit. Without an explicit type attribute, any button will trigger form submission, meaning UI controls like toggles or close buttons need type="button" to avoid this behavior.

Do all buttons inside a form need an explicit type attribute?

Yes, all buttons inside a form should have an explicit type attribute. Setting type="button" for UI interactions and type="submit" for actual submissions ensures non-submitting controls do not accidentally trigger form submission behavior.

How do I fix a button triggering a form submit unexpectedly in HTML?

To fix unexpected form submits in HTML, add the explicit type="button" attribute to your non-submitting UI buttons. This overrides the default submit behavior and prevents actions like closing a modal from submitting the parent form.

Can I use this approach to fix default button behavior across other UI frameworks?

Yes, enforcing explicit type attributes applies across HTML and React as well as other frameworks. Documenting button type patterns prevents accidental form submissions regardless of the UI library managing the form structure.