:state()
pseudo-class. This is handy to conditionally override the exposed CSS variables (e.g. --p-button-bg and
--p-button-fg) without having to duplicate the state logic in your application.loadingloading is truep-button:state(loading) {
--p-button-bg: light-dark(#025b3f, #21eeae);
--p-button-fg: light-dark(#21eeae, #025b3f);
}
CustomStateSet or the :state()
pseudo-class simply ignore these rules, the button keeps working and falls back to its default styling. Be aware that
custom states can't be expressed during server side rendering, they are only applied once the component is hydrated on
the client. Therefore, don't rely on :state() for styling that has to be correct on first paint.p-button:disabled (the button is form-associated)p-button:not(:disabled, :state(loading)):hoverp-button:focus-visible<p-button class="my-button" variant="secondary">:disabled pseudo-class as soon as
the disabled attribute is set — no custom state is needed for it.p-button {
--p-button-bg: light-dark(#025b3f, #21eeae);
--p-button-fg: light-dark(#21eeae, #025b3f);
}
p-button:not(:disabled, :state(loading)):hover {
--p-button-bg: light-dark(#013d2a, #6ef7cf);
--p-button-fg: light-dark(#6ef7cf, #013d2a);
}
p-button:disabled {
--p-button-bg: light-dark(#6f3d0b, #ffaa4f);
--p-button-fg: light-dark(#ffaa4f, #6f3d0b);
}
