Text colour ----------- Against solid backgrounds this works fairly well: hsl( from var(--row-colour) h s calc(sign(l - 51) * -100) ) But doesn't work for some lighter and mid-tone colours like lime, cyan, and yellow. Lab colour space works better for this: lab( from var(--row-colour) calc(sign(l - 70) * -100) 0 0 / 1 ) General ------- Lightness Inversion: hsl h s calc(100 - l) Darken: hsl h s calc(l / 2) Lighten: hsl h s calc(l + (100 - l) / 2)