Programmatically choose high-contrast colors

前端 未结 10 721
野的像风
野的像风 2020-12-14 07:29

This should be a simple question, but I haven\'t been able to find a way to make it work.

Essentially, I have a silly localhost page that I use in my webdevelopment.

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 07:55

    "Contrast" is a loaded word. If you just care about being able to read the text, then one easy way is to work in a luminance-based color space like HSL, and pick foreground and background colors with big differences in luminance.

    The conversion between HSL and RGB is well-known--see Wikipedia for the details.

    If you're talking about actual color contrast, it's not nearly as cut-and-dried (there are a lot of perceptual factors that, as far as I know, haven't been reduced to a single colors space), but I suspect you don't need that level of sophistication.

提交回复
热议问题