brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: all: unset in CSS strips a button bare, so add the focus ring back

Css
~/tips/tip-css-all-unset-button-reset

all: unset;

One declaration removes every browser style from an element, including some you want to keep.

When I want a button that looks like plain text, removing border, background, padding, font and color one by one is tedious. all resets nearly every property in one go.

.text-button {
  all: unset;
  cursor: pointer;
}
.text-button:focus-visible {
  outline: 2px solid #0b6bcb;
  outline-offset: 2px;
}

all: unset sets every property to its inherited value if the property inherits (like color and font), and to its initial value if it does not (like border, padding and display). The button now takes its font and color from its parent and has no box of its own. The element stays a real button, so keyboard and screen reader behavior is unchanged.

Two other values are worth knowing: all: revert rolls back to the browser’s own styles, which is often what you really want, and all: initial ignores inheritance as well.

The catch is that the focus ring is gone too, since outline resets to none. Keyboard users then cannot see where they are, which is why the second rule is not optional. Also note that display becomes inline, so width and padding behave differently than you might expect. MDN notes that all leaves direction and unicode-bidi alone.

Further reading: MDN: all

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link