CSS Form Styling Module Level 1

Unofficial Proposal Draft,

More details about this document
This version:
https://drafts.csswg.org/css-forms/
Issue Tracking:
CSSWG Issues Repository
Inline In Spec
Editor:
(Apple Inc.)
Suggest an Edit for this Spec:
GitHub Editor
Not Ready For Implementation

This spec is not yet ready for implementation. It exists in this repository to record the ideas and promote discussion.

Before attempting to implement this spec, please contact the CSSWG at www-style@w3.org.


Abstract

This document is currently a loosely-structured set of ideas and inspiration for CSS form styling. It is not an implementable standard. Do not look at this as anything but a collection of ideas.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-forms” in the title, like this: “[css-forms] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list www-style@w3.org.

This document is governed by the 03 November 2023 W3C Process Document.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

1. Pseudo-Elements

This section defines some pseudo-elements for styling parts of form elements.

1.1. Styling form control pickers: the ::picker() pseudo-element

The ::picker() pseudo-element targets the popup picker of form control elements which have popup pickers, such as the select element. It is an element-backed pseudo-element.

::picker() = ::picker( <ident>+ )

Note: Once all of the controls that might support picker styling have it, then we might add a (no-argument) ::picker pseudo-element as well.

The ::picker() pseudo-element only matches when the originating element supports base appearance and has a popup picker. The specified <ident> must also match the unique picker name of the originating element. For example, the unique picker name for the select element is "select".

Since it is an element-backed pseudo-element, There is no restriction on which properties apply to the ::picker() pseudo-element.

In order for the ::picker() pseudo-element to be rendered, it and its originating element must be rendered with base appearance by applying appearance: base to both of them.

<style>
  select, select::picker(select) {
    appearance: base;
  }
  select::picker(select) {
    border: 5px solid red;
    background-color: blue;
  }
</style>

1.2. Picker opener icon: the ::picker-icon pseudo-element

The ::picker-icon pseudo-element is only generated when the originating element has base appearance and opens a picker.

::picker-icon is a tree-abiding pseudo-element. It accepts all properties. It inherits from its originating element.

::picker-icon generates a box as if it was an child of its originating element, after any boxes generated by the ::after pseudo-element, with content as specified by content.

1.3. Checkmark icon: the ::checkmark pseudo-element

The '::checkmark'' pseudo-element is only generated when the originating element supports the :checked pseudo-class and either has base appearance or an ancestor with base appearance.

::checkmark is a tree-abiding pseudo-element. It accepts all properties. It inherits from its originating element.

::checkmark generates a box as if it was an child of its originating element, preceding any boxes generated by the ::before pseudo-element, with content as specified by content.

1.4. Styling parts of slider-like controls: the ::slider-thumb, ::slider-track, ::slider-fill and ::slider-options-track pseudo-elements

Slider-like controls are form controls that represent progress. That progress may be adjustable by the user.

The list of slider-like controls depends on the host language. For HTML, this corresponds to:

The following pseudo-elements are provided to style their different parts:

::slider-thumb
The ::slider-thumb pseudo-element represents the portion that allows the user to adjust the progress of the control.

That portion may be omitted for controls where the progress is not adjustable. Disabled controls should provide this portion if the enabled state allows adjusting the progress.

NOTE: It is typically natively rendered as a circle in most user agents.

::slider-track
The ::slider-track pseudo-element represents the portion containing both the progressed and unprogressed portions of the control.
::slider-fill
The ::slider-fill pseudo-element represents the portion containing the progressed portion of the control.

When the progress of control is undetermined (like with <progress indeterminate>), the user agent is expected to give this portion an inline-size of zero.

::slider-options-track
The ::slider-options-track pseudo-element represents the portion containing the options. It is expected to render at the same width as ::slider-track and underneath it in the block direction.

With `appearance: auto`, the user agent may draw tickmarks corresponding to the options given by the associated ` `.

These pseudo-elements are tree-abiding pseudo-elements and their structure is expected to be the following:

<input type="range">
├─ ::slider-track
│  └─ ::slider-fill
├─ ::slider-thumb
└─ ::slider-options-track

Appendix: Explorations

Basic Styling Proposals

This section sketches a few proposals for solving the form styling problem.

Prototypes

This idea, originally suggested by fantasai, is that we can style a handful of "prototype" elements. Browser UI designers can then take the styling of those elements and extrapolate the design into their own UIs. At minimum, things like text, backgrounds, and borders can be used. At the limit, things like internal padding, border-radius, etc might be used.

@control button {
  <declaration-list>
}

@control input {
  <declaration-list>
}

input::selection {
  <declaration-list>
}

...
You would be able to use styles for:

Most form controls, even a calendar widget or clock, are a combination of these three primitives in some way. If the UA is given the styling for these three primitives, and perhaps one or two more it can figure out how to style the rest.

For example, a calendar widget might have the month, the year, some buttons to move them around, the ability to click into them and edit them directly, and a representation of the days of the month. The selected day is selected. Perhaps the buttons only show up on :hover or :focus -- the UA decides. But it knows that a button should be this particular shade of blue with that particular border-radius and drop-shadow. The calendar might be shown in the colors of the input field, and the selected day in the selection color, and in all ways it will match the way the input fields look in the rest of the page.

Now, the author can’t decide, for example, the spacing between the year and the month name, or whether the button to change years has a solid arrow or a hollow arrow or a frilly one, and she can’t decide that there should be a black solid half-border between the month and the day field below it with 5px spacing. But the calendar will look like it belongs to the page, and the UA can come up with a different calendar layout when it ships one on a wide but short smart watch where the month and year are better placed on the side without breaking anything.

The black area is the button color; a very light transparency of it can be the glass color. The rollers are the input colors.
It’s hard to tell without more context, but for the one on the right, the clock face and the digital readout are @input colors, the highlighted bits are the highlight color, the Done button is the button styling, and the shaded area around the clock face is the same color as the button background.

Inverse System Colors

This idea, originally sketched by Florian and Tab, is to define an abstract set of colors that UI designers can then choose from when coloring their UI.

Tab’s suggested set of colors, from an Android color-extraction API proposal:

(where light ~75% lightness, normal is ~50%, dark is ~25%; vibrant is at least 30% saturation, ideally 100%, and muted is at most 40% saturation, ideally 30%)

That’s 11 colors, many of which should be drawable from the webpage’s own color scheme. We can auto-gen a bunch of them if you specify at least some of them, like genning the light/dark variants from the "normal-vibrant" color, or automatically setting text colors to white/black as appropriate.

There’s no guarantee that the input UIs will use the colors in the *same way* that the rest of the page does, though.

Miscellaneous Control-Specific Suggestions

<progress> and <meter> styling

Insert <select> and <datalist> styling proposal and/or whiteboard photo.

Select/Datalist Dropdown

  1. Only allow styling if both color and background are set.

  2. Option container:

    • backgrounds

    • borders

    • padding

  3. option

    • padding

    • borders

    • border-collapse?

    • backgrounds

    • display-inside is allowed, automatically blockified

    • not margins, position, float, width, height

    All options are contain:paint and BFCs.

Input UI Examples

This section catalogues as many input UI examples as we can screenshot, especially on mobile devices where they’re a bit "weirder".

Time Pickers

iOS time picker
Android time picker 1
Android time picker 2

Date Pickers

Android date picker

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-BACKGROUNDS-3]
Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. URL: https://drafts.csswg.org/css-backgrounds/
[CSS-COLOR-4]
Chris Lilley; Tab Atkins Jr.; Lea Verou. CSS Color Module Level 4. URL: https://drafts.csswg.org/css-color-4/
[CSS-CONTENT-3]
Elika Etemad; Dave Cramer. CSS Generated Content Module Level 3. URL: https://drafts.csswg.org/css-content-3/
[CSS-PSEUDO-4]
Daniel Glazman; Elika Etemad; Alan Stearns. CSS Pseudo-Elements Module Level 4. URL: https://drafts.csswg.org/css-pseudo-4/
[CSS-UI-4]
Florian Rivoal. CSS Basic User Interface Module Level 4. URL: https://drafts.csswg.org/css-ui-4/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. URL: https://drafts.csswg.org/css-values-4/
[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[SELECTORS-4]
Elika Etemad; Tab Atkins Jr.. Selectors Level 4. URL: https://drafts.csswg.org/selectors/

Issues Index

<progress> and <meter> styling
Insert <select> and <datalist> styling proposal and/or whiteboard photo.