Etiqueta HTML <botón>
Ejemplo
Un botón en el que se puede hacer clic está marcado de la siguiente manera:
<button type="button">Click Me!</button>
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La <button>
etiqueta define un botón en el que se puede hacer clic.
Dentro de un <button>
elemento puedes poner texto (y etiquetas como <i>
, <b>
,
<strong>
, <br>
, <img>
, etc.). ¡Eso no es posible con un botón creado con el <input>
elemento!
Sugerencia: especifique siempre el type
atributo de un <button>
elemento para indicar a los navegadores qué tipo de botón es.
Consejo: ¡Puede diseñar botones fácilmente con CSS! Mire los ejemplos a continuación o visite nuestro tutorial de Botones CSS .
Compatibilidad con navegador
Element | |||||
---|---|---|---|---|---|
<button> | Yes | Yes | Yes | Yes | Yes |
Atributos
Attribute | Value | Description |
---|---|---|
autofocus | autofocus | Specifies that a button should automatically get focus when the page loads |
disabled | disabled | Specifies that a button should be disabled |
form | form_id | Specifies which form the button belongs to |
formaction | URL | Specifies where to send the form-data when a form is submitted. Only for type="submit" |
formenctype | application/x-www-form-urlencoded multipart/form-data text/plain |
Specifies how form-data should be encoded before sending it to a server. Only for type="submit" |
formmethod | get post |
Specifies how to send the form-data (which HTTP method to use). Only for type="submit" |
formnovalidate | formnovalidate | Specifies that the form-data should not be validated on submission. Only for type="submit" |
formtarget | _blank _self _parent _top framename |
Specifies where to display the response after submitting the form. Only for type="submit" |
name | name | Specifies a name for the button |
type | button reset submit |
Specifies the type of button |
value | text | Specifies an initial value for the button |
Atributos globales
La <button>
etiqueta también es compatible con los atributos globales en HTML .
Atributos de eventos
La <button>
etiqueta también es compatible con los atributos de eventos en HTML .
Más ejemplos
Ejemplo
Use CSS para diseñar botones:
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display:
inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {background-color:
#4CAF50;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
</style>
</head>
<body>
<button class="button
button1">Green</button>
<button class="button button2">Blue</button>
</body>
</html>
Ejemplo
Use CSS para dar estilo a los botones (con efecto de desplazamiento):
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display:
inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: white;
color: black;
border: 2px
solid #4CAF50;
}
.button1:hover {
background-color: #4CAF50;
color: white;
}
.button2 {
background-color: white;
color:
black;
border: 2px solid #008CBA;
}
.button2:hover {
background-color: #008CBA;
color: white;
}
</style>
</head>
<body>
<button class="button button1">Green</button>
<button class="button
button2">Blue</button>
</body>
</html>
páginas relacionadas
Referencia HTML DOM: objeto de botón
Tutorial de CSS: Aplicar estilo a los botones
Configuración predeterminada de CSS
Ninguna.