Skip to content

Instantly share code, notes, and snippets.

@janispritzkau
Last active October 12, 2025 12:19
Show Gist options
  • Save janispritzkau/589e2d7961d7ebb2b21886ac6dc9c489 to your computer and use it in GitHub Desktop.
Save janispritzkau/589e2d7961d7ebb2b21886ac6dc9c489 to your computer and use it in GitHub Desktop.
`on-bg` utility for Tailwind CSS emulating Material 3 state layers.
<button class="
  rounded-lg border-outline-subtle bg-container state-button p-4 text-start
  hover:on-bg-on-surface/hover active:on-bg-on-surface/active
">
@utility on-bg-* {
--tw-gradient-to: --value(--on-bg-color-*, --color-*, [*]);
--tw-gradient-to: color-mix(
in srgb,
--modifier(--on-bg-opacity-*, [*]) --value(--on-bg-color-*, --color-*, [*]),
transparent
);
--tw-gradient-to: color-mix(
in srgb,
calc(--modifier(integer) * 1%) --value(--on-bg-color-*, --color-*, [*]),
transparent
);
background-image: linear-gradient(var(--tw-gradient-to) 0 0);
}
@utility state-button {
@apply on-bg-transparent transition-colors active:duration-75 active:ease-out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment