About this set
Three buttons that confirm what they did by changing their label and colour. Add to cart turns green and reads Added, Follow turns into an outlined Following, and Copy code turns pale green and reads Copied for two seconds. Use the first two for on and off choices a shopper or reader can undo, and the copy button beside code samples, coupon codes or share links. Add to cart and Follow are toggle buttons: a short script flips aria-pressed on click, and the CSS swaps the visible label from that attribute. The resting label is not removed but visually hidden, so the accessible name stays Add to cart or Follow and screen readers announce it as pressed or not pressed. The copy button writes the text in its data-copy attribute to the clipboard with the Clipboard API, sets data-done for two seconds and announces Copied to clipboard, or a failure message, through a visually hidden status region. Each button keeps a 172 pixel minimum width so the label swap does not move the layout. The Bootstrap version restyles .btn through the –bs-btn-* variables, and the Tailwind version uses group-aria-pressed and group-data-done variants.
What’s included
- Add to cart, Follow and Copy code buttons
- Toggle state kept in aria-pressed, styled from the attribute
- Accessible name stays the same when the visible label changes
- Copy result announced through a role="status" region
- Fixed minimum width so the label swap does not shift the layout
Accessibility
All three are native buttons. The cart and follow buttons carry aria-pressed, and their resting label stays in the accessible name as visually hidden text while the confirmation label is aria-hidden, so the name does not change with the state. The copy button reports success or failure through a visually hidden role="status" paragraph. Keyboard focus draws a 2px indigo outline or ring, and colour transitions are removed under prefers-reduced-motion. The confirmed green was darkened to #15803d so the white label reaches 4.5:1.
Customise it
Change the colours in .morph-cart, .morph-follow and .morph-copy and their [aria-pressed=true] or [data-done] rules, and the text to copy in the data-copy attribute. In Bootstrap edit the --bs-btn-bg and --bs-btn-color variables on the same classes; in Tailwind edit the bg-, aria-pressed: and data-done: utilities.

















