← Back to HTML Course | Chapter 3: Page Structure | Lesson 12 of 12

HTML Buttons

सोचिए आप किसी elevator के पास जाते हैं। उसमें metal buttons का एक panel होता है: चौथी मंज़िल पर जाने के लिए आप 4 दबाते हैं, या emergency में Alarm button दबाते हैं। हर button का एक खास काम होता है, और उसे click करने से एक action trigger होता है। HTML buttons वही elevator controls हैं। ये आपके page पर clickable interaction elements को define करते हैं। आप इनका उपयोग form data submit करने, custom JavaScript actions trigger करने, या input fields reset करने के लिए कर सकते हैं। सही button type और styles सेट करके, आप अपने page के साथ interact करना सभी users के लिए आसान बनाते हैं।
Syntax
markup
<button type="button" onclick="script">Label</button>

button Tag

button tag आपके webpage पर एक interactive, clickable button define करता है। इस container element के अंदर, आप अपने button का दिखावट customize करने के लिए text, icons, या images रख सकते हैं।

Note:
  • अनचाहे browser behaviors से बचने के लिए हर button पर हमेशा एक explicit type attribute तय करें।
  • Accepted attributes:
  • type — submit | reset | button
  • name / value — form के साथ submit होने वाला data
  • disabled — boolean
  • form — जुड़े हुए form की id
  • formaction / formmethod / formtarget — form की settings override करें
Warning: button tag self-closing नहीं है; आपको closing tag लिखनी ही होगी, भले ही आपके button में सिर्फ एक icon हो।

उदाहरण: The button Tag

markup
<button>Click me</button>

Button Types Define करना

आप type attribute का इस्तेमाल करके तीन अलग-अलग button types define कर सकते हैं: submit (जो form data को package करके भेजता है), reset (जो सभी fields को clear करता है), और button (जो custom JavaScript actions trigger करता है)।

Note:
  • page को reload होने से रोकने के लिए, custom scripts trigger करने वाले buttons पर type="button" इस्तेमाल करें।
  • Accepted values:
  • type="submit" — form submit करता है (form के अंदर default)
  • type="reset" — form controls reset करता है
  • type="button" — कोई default behavior नहीं
Warning: अगर आप type attribute specify नहीं करते, तो browsers forms के अंदर button को by default एक submit button की तरह treat करेंगे।

उदाहरण: Defining Button Types

markup
<button type="submit">Submit</button>
<button type="reset">Reset</button>
<button type="button">Run Script</button>

Buttons को Disable करना

आप किसी button के opening tag में disabled attribute जोड़कर उसे temporarily lock या disable कर सकते हैं। इससे button ग्रे हो जाता है, user clicks रुक जाते हैं, और किसी भी जुड़े हुए script triggers को रोक देता है।

Note:
  • किसी फ़ाइल के upload होते समय users को submit button को कई बार क्लिक करने से रोकने के लिए disabled attribute इस्तेमाल करें।
  • Accepted values:
  • disabled — boolean attribute (मौजूद हो या disabled="")
  • Disabled buttons पर क्लिक, focus या submit नहीं किया जा सकता
Warning: Disabled buttons को keyboard navigation के दौरान पूरी तरह ignore कर दिया जाता है, इसलिए users Tab key का उपयोग करके उन पर focus नहीं कर सकते।

उदाहरण: Disabling Buttons

markup
<button disabled>Uploading...</button>

CSS से Buttons को Style करना

Browsers buttons को boxy, पुराने ढंग के default styles में render करते हैं। आप standard CSS properties इस्तेमाल करके उनके borders, background colors, padding, और hover states को आसानी से customize कर सकते हैं।

Note: क्लिक करने पर buttons को highly responsive महसूस कराने के लिए उनकी styles में custom hover और active states जोड़ें।
Warning: browser focus outlines को custom focus styles से replace किए बिना उन्हें छिपाने के लिए CSS outline: none का उपयोग कभी न करें।

उदाहरण: Styling Buttons with CSS

markup
<button style="background-color: blue; color: white; padding: 10px; border: none;">
  Styled Button
</button>

Accessible Button Labels

अगर आपके button में बिना किसी दिखने वाले text के सिर्फ एक icon (जैसे trash can या pencil symbol) है, तो screen readers के लिए उसे समझना मुश्किल हो जाता है।

दृष्टिबाधित users को यह बताने के लिए कि button क्या करता है, आपको एक descriptive aria-label attribute शामिल करना चाहिए।

Note: किसी भी icon-only button की क्रिया बताने के लिए हमेशा एक aria-label जोड़ें।
Warning: accessibility labels न जोड़ने से आपके interactive menus screen-reader users के लिए पूरी तरह unusable हो सकते हैं।

उदाहरण: Accessible Button Labels

markup
<button aria-label="Delete item">🗑</button>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
🔒

Chapter Quiz — Complete all 12 topics to unlock

0/12 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.