typestar

Every state a button has in CSS

Hover is the easy one. The other five are what makes it feel finished.

.button {
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  background: #2b6cb0;
  color: white;
  transition: background 120ms ease;
}

.button:hover { background: #24578f; }
.button:active { background: #1d456f; transition: none; }

.button:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

.button:disabled { background: #cbd5e1; color: #64748b; cursor: not-allowed; }

How it works

  1. :focus-visible shows a ring for the keyboard and not for the mouse.
  2. :active should be instant; a transition on it feels laggy.
  3. :disabled must look unavailable without becoming unreadable.

Keywords and builtins used here

The run, in numbers

Lines
18
Characters to type
413
Tokens
98
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 69 seconds.

Type this snippet

Step 1 of 2 in Controls, step 1 of 13 in Styling components.

Next →