Skip to content

[css-forms-1] Styles for color input #12142

Open
@lukewarlow

Description

@lukewarlow

As currently specced the color input never renders the actual chosen color. We need to specify styles specific to the color input. This will track that.

Proposed additions

::color-swatch {
    /* Ensures contrast between chosen color and button background (which by default is transparent so the page background) */
    border: 1px solid currentColor;

    /* Gives a reasonable default size */
    inline-size: 2em; 
    block-size: 1em;

    /* Ensures it fills it's parent container */
    flex: 1; 

    /* Should this be here? It's designed to prevent forced dark mode from messing with the colour? */
    color-scheme: light only;
     
    /* Prevents forced colors mode breaking the input */
    forced-color-adjust: none;

    /* This uses a linear gradient to handle showing the alpha of the control value. */
    background: linear-gradient(control-value(<color>)),
      linear-gradient(to bottom right, black 50%, white 50%);

    box-sizing: border-box;
}

This should result in the below rendering given <input type="color" value="color(srgb 0 1 0 / 0.75)" alpha>

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions