The HTML <button> Element

Publish in HTML Tutorial el 23/05/2025 15:20

The <button> element creates a clickable button that can trigger actions on a webpage. Buttons can submit forms, trigger JavaScript functions, or perform other interactive tasks. Unlike <input type="button">, the <button> element can contain HTML content (text, images, etc.) and offers more styling flexibility.


Basic Button Examples

Here are simple examples of how to use the <button> element:


1. Simple Button

A basic button with text content:

Play Code


2. Button with Icon

A button containing both text and an icon (using UTF8 Icons in this example):

Play Code


3. Disabled Button

A button that is disabled and cannot be clicked:

Play Code


Buttons with JavaScript

These examples demonstrate buttons that trigger JavaScript functions:

4. Button with Click Event

A button that shows an alert when clicked:

Play Code


5. Button that Changes Content

A button that modifies the page content when clicked:

Play Code


Button Attributes

Here are some important attributes for the <button> element:


Best Practices

  • Always specify the type attribute (button, submit, or reset)
  • Provide meaningful text or labels for buttons
  • Use ARIA attributes when needed for accessibility
  • Style buttons consistently throughout your application
  • Ensure buttons have sufficient size for easy interaction

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...