CSS :not()
Updated on
Last site update: 8 May 2024
Inverse of :is()
check out :not(), which does the opposite and excludes the selectors passed to it.
– Caity Opelka
Examples
Here are some examples…
1* + *:not(li, dt, h4) {
2 margin-top: 1em;
3}
- This selects every element that follows another unless it’s a list item, a term
- definition term or an h4 header.
1img:not([alt]) {
2 outline: 2px solid red;
3}
This uses an attribute selector and puts an outine around any images that don’t have an alt
attribute.