Search code examples
htmlcsscolors

Why is "field" a valid color name in CSS?


I have created a function isColor that relies on CSS.supports to determine whether some text is an HTML color or not. This works perfect for color names like red and hex colors like #3883fa. However, for the text field, the function CSS.supports('color', 'field') returns true too. The name field is not mentioned in the list with CSS color names, and I would expect CSS.supports to return false in this case.

Why is this the case? Are there other cases like this?


Solution

  • It's a system color meaning the background color of an input field, as defined at Field in the latest draft of CSS Color Module Level 4.


    As noted in the question comments, CSS.supports tests for CSS colors, which doesn't apply the "error correction" algorithm used by colors in HTML attributes. For that, practically every string of characters gets interpreted as a color when used in an HTML attribute that expects a color value.