Saltar al contenido
Botón·Gratis

Juego de botones (HTML + CSS)

Botones principal, secundario, de peligro y discreto en CSS puro, con estados desactivado y de carga. Cada uno mide al menos 44 × 44 px y muestra un anillo de foco al usar el teclado. El modo oscuro cambia los colores sin perder contraste.

Se instala gratis.

Si tienes PocketCode instalado en tu Android, esto abre la página en la app.

Vista previa

buttons.html · 77 líneas
<!--
  Button set in plain HTML and CSS: primary, secondary, danger and quiet, plus a loading state.
  Every button is at least 44 x 44 px and shows a focus ring when reached with the keyboard.
  While a request runs, set aria-busy="true" and aria-disabled="true" on the button: the label is hidden
  behind a spinner but screen readers still read it. aria-disabled does not block clicks, so your click
  handler should return early while aria-busy is set. Remove both attributes when it finishes.
  Colours live in the CSS variables; dark mode follows the system setting.
-->
<style>
  .btn {
    --btn-bg: #1f5fd1;
    --btn-fg: #ffffff;
    --btn-border: transparent;
    --btn-ring: #1f5fd1;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid var(--btn-border);
    border-radius: 10px;
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: 600 15px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    text-decoration: none;
    cursor: pointer;
    transition: filter 0.15s ease;
  }
  .btn-secondary { --btn-bg: transparent; --btn-fg: #1f5fd1; --btn-border: #7c7c88; }
  .btn-danger { --btn-bg: #b3261e; --btn-fg: #ffffff; --btn-ring: #b3261e; }
  .btn-quiet { --btn-bg: transparent; --btn-fg: #1b1b1f; --btn-ring: #1b1b1f; }

  @media (prefers-color-scheme: dark) {
    .btn { --btn-bg: #8ab4ff; --btn-fg: #0b1a33; --btn-ring: #8ab4ff; }
    .btn-secondary { --btn-bg: transparent; --btn-fg: #8ab4ff; --btn-border: #7c7c88; }
    .btn-danger { --btn-bg: #ffb4ab; --btn-fg: #5c0f0a; --btn-ring: #ffb4ab; }
    .btn-quiet { --btn-bg: transparent; --btn-fg: #ececf1; --btn-ring: #ececf1; }
  }

  .btn:hover { filter: brightness(1.1); }
  .btn:active { filter: brightness(0.92); }
  .btn:focus-visible { outline: 2px solid var(--btn-ring); outline-offset: 2px; }
  .btn:disabled,
  .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; filter: none; }

  .btn[aria-busy="true"] { opacity: 1; color: transparent; cursor: progress; }
  .btn[aria-busy="true"]::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid var(--btn-fg);
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.8s linear infinite;
  }
  @keyframes btn-spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) {
    .btn { transition: none; }
    .btn[aria-busy="true"]::after { animation-duration: 2.4s; }
  }

  .btn-row { display: flex; flex-wrap: wrap; gap: 12px; }
</style>

<div class="btn-row">
  <button class="btn" type="button">Save changes</button>
  <button class="btn btn-secondary" type="button">Cancel</button>
  <button class="btn btn-danger" type="button">Delete</button>
  <button class="btn btn-quiet" type="button">Skip for now</button>
  <button class="btn" type="button" aria-busy="true" aria-disabled="true">Saving</button>
  <button class="btn" type="button" disabled>Not available</button>
  <a class="btn btn-secondary" href="#pricing">See pricing</a>
</div>

Cambios en la 1.0.0

Primera versión.

Relacionados

Botón (React + Tailwind)GratisBotónBotón en TypeScript con estilo principal y secundario, anillo de foco visible y un indicador de carga que además activa aria-busy. El estilo secundario tiene colores para el modo oscuro.Botón asíncrono (Vue)GratisBotónUn botón de Vue 3 que ejecuta una acción asíncrona, enseña un indicador de carga mientras espera e ignora más toques hasta que acaba. Emite done o error, así que tú decides qué mostrar después. TypeScript, sin librerías.Botón principal (Compose)GratisBotónBotón de Material 3 que vibra un instante al tocarlo. Con loading = true muestra un indicador de carga e ignora los toques mientras dura una petición.Formulario de contacto (HTML + CSS)GratisPáginaUn formulario de contacto en un solo fichero HTML: nombre, email, un tema opcional y el mensaje. Cada campo tiene su etiqueta y solo se marca en rojo cuando alguien ha escrito en él o ha intentado enviar. Pon en action la dirección de tu servidor. El modo oscuro sigue al sistema.Botón de copiar (React)GratisBotónBotón de React y TypeScript que copia un texto al portapapeles. Muestra «Copied» dos segundos y una línea de estado oculta avisa al lector de pantalla. No necesita framework de CSS. En páginas servidas por http sin cifrar usa el comando de copiar antiguo.Interruptor (Svelte)GratisBotónUn interruptor de encendido y apagado para Svelte 5 hecho con un botón con role switch, así que Espacio, Intro y los lectores de pantalla funcionan. Enlaza checked o pasa onchange. Tiene una segunda línea opcional, estado desactivado y colores en variables CSS.