Skip to content

Commit e0e00fa

Browse files
committed
[css-ui-4] Add the 'appearance' property
1 parent 0b7d98d commit e0e00fa

2 files changed

Lines changed: 555 additions & 16 deletions

File tree

css-ui-4/Overview.bs

Lines changed: 188 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ Group: csswg
1010
Status: UD
1111
Editor: Florian Rivoal, Invited Expert, florian@rivoal.net, http://florian.rivoal.net
1212
Ignored Terms: box-sizing, resize, text-overflow, caret-color, nav-up, nav-down, nav-left, nav-right
13-
13+
Link Defaults: css-position-3 (property) position
14+
Link Defaults: css21 (property) float
15+
Link Defaults: css21 (property) clear
16+
Link Defaults: selectors-4 (selector) :checked
1417
Abstract: This is a delta specification over CSS-UI Level 3.
1518
Once the level 3 specification is final,
1619
its content will be integrated into this specification,
@@ -116,7 +119,7 @@ Abstract: This is a delta specification over CSS-UI Level 3.
116119
except on <a>editable element</a>s
117120
where the computed value is always ''user-select/element''
118121
regardless of the specified value,
119-
and when the specified value is ''auto'',
122+
and when the specified value is ''user-select/auto'',
120123
which computes one of the other values as defined below.
121124

122125
For the purpose of this specification,
@@ -128,20 +131,20 @@ Abstract: This is a delta specification over CSS-UI Level 3.
128131

129132
<dl dfn-type=value dfn-for=user-select>
130133
<dt><dfn>auto</dfn>
131-
<dd>The computed value of ''auto'' is determined as follow:
134+
<dd>The computed value of ''user-select/auto'' is determined as follow:
132135
<ul>
133136
<li>If the element is an <a>editable element</a>
134137
the computed value is ''element''
135138
<li>Otherwise, if the element is not absolutely positioned
136139
and the computed value of 'user-select' on the parent of this element is ''all'',
137140
the computed value is ''all''
138141
<li>Otherwise, if the element is not absolutely positioned
139-
and the computed value of 'user-select' on the parent of this element is ''none'',
140-
the computed value is ''none''
142+
and the computed value of 'user-select' on the parent of this element is ''user-select/none'',
143+
the computed value is ''user-select/none''
141144
<li>Otherwise, the computed value is ''text''
142145
</ul>
143146

144-
Note: This unusual combination of a non inherited property with an initial value of ''auto''
147+
Note: This unusual combination of a non inherited property with an initial value of ''user-select/auto''
145148
whose computed value depends on the parent element
146149
makes it possible to create what is effectively selective inheritance.
147150
This was initially proposed by Microsoft in IE to introduce a behavior similar to inheritance
@@ -156,14 +159,14 @@ Abstract: This is a delta specification over CSS-UI Level 3.
156159
is not restricted to textual elements, and may contain tables, images...
157160
The webkit documentation claims their implementation of text only selects text,
158161
while auto selects anything,
159-
but sine webkit computes ''auto'' into ''text'',
162+
but sine webkit computes ''user-select/auto'' into ''text'',
160163
this does not match reality.
161164

162165
<dt><dfn>none</dfn>
163166
<dd>Users cannot select the content of the element.
164167
No selection may be started in this element.
165168

166-
However, if this element has descendants on which the computed value of 'user-select' is not ''none'',
169+
However, if this element has descendants on which the computed value of 'user-select' is not ''user-select/none'',
167170
these descendants can be selected.
168171

169172
A selection started outside of this element may not end in this element.
@@ -184,15 +187,15 @@ Abstract: This is a delta specification over CSS-UI Level 3.
184187
A selection may extend across this element.
185188
In this case, browsers which support multiple ranges per selection
186189
may exclude this element from the selection.
187-
If the element has descendants on which 'user-select' does not compute to ''none'',
190+
If the element has descendants on which 'user-select' does not compute to ''user-select/none'',
188191
these descendants must be included in a selection extending across the element.
189192

190-
Note: ''none'' is not a copy protection mechanism,
193+
Note: ''user-select/none'' is not a copy protection mechanism,
191194
and using it as such is ineffective:
192195
it will have no effect on legacy User Agents that do not support it,
193196
and the user can disable it through the user style sheet or equivalent mechanisms
194197
on UAs that do anyway.
195-
Instead, ''none'' is meant to
198+
Instead, ''user-select/none'' is meant to
196199
make it easier for the user to select the content they want,
197200
by letting the author disable selection on UI elements
198201
that are not useful to select.
@@ -232,6 +235,180 @@ Abstract: This is a delta specification over CSS-UI Level 3.
232235
Issue: the list above is incomplete, and needs to include
233236
at least the various button-like variants of <{input}>.
234237

238+
<h2 id="form-styling">Form Control Styling</h2>
239+
240+
<h3 id="appearance-switching">Switching appearance</h3>
241+
242+
While the way most elements in a document look can be fully controlled by CSS,
243+
form controls are typically rendered by UAs using native UI controls of the host operating system,
244+
which can neither be replicated nor styled using CSS.
245+
246+
This specification introduces the 'appearance' property
247+
to provide some control over this behavior.
248+
In particular, using ''appearance: none'' allows authors
249+
to suppress the native style of form controls,
250+
so that CSS can be used to fully restyle them.
251+
252+
<pre class="propdef">
253+
Name: appearance
254+
Value: ''auto'' | ''none'' | ''button''
255+
Initial: auto
256+
Applies To: all elements
257+
Inherited: no
258+
Computed value: As specified
259+
Media: all
260+
</pre>
261+
262+
Issue: Should ''appearance/auto'' compute to ''appearance/none'' on regular elements?
263+
I would say no:
264+
to be consistent, we should then have ''appearance/auto'' compute to ''button'' on buttons, etc.
265+
If we did that,
266+
every time we introduced a new value,
267+
we would change what ''appearance/auto'' computes to on some elements,
268+
which doesn't sounds desirable.
269+
270+
Note: This specification intentionally refrains from making the appearance
271+
of all possible form controls and sub controls available as values,
272+
as had previously been attempted by several browser vendors in experimental implementations.
273+
Experience as shown that such a list would be extremely long and not practical to maintain.
274+
Moreover, most values of such an enumeration are never used by authors.
275+
UAs cannot therefore use the 'appearance' in the UA stylesheet to give each control is native look and feel,
276+
and must use ''appearance:auto'' instead.
277+
Only values which are useful to authors or in a user stylesheet
278+
and for which interoperability can be achieved will be provided
279+
in addition to ''appearance/auto'' and ''appearance/none''.
280+
281+
Issue: IE supports -webkit-appearance, and also includes the textfield value.
282+
Presumably this was done due to compatibility problems,
283+
so we may want to include it as well.
284+
285+
<dl dfn-type=value dfn-for=appearance>
286+
<dt><dfn>auto</dfn>
287+
<dd>UAs may render form controls using native controls of the host operating system
288+
or with a look and feel not other expressible in CSS.
289+
290+
Elements other than form controls must be rendered as if ''appearance/none'' had been specified.
291+
<dt><dfn>none</dfn>
292+
<dd>The element is rendered following the usual rules of CSS.
293+
Replaced elements other than form controls are not affected by this,
294+
and remain replaced elements.
295+
From controls are <em>not</em> made to look like native controls of the host operating system.
296+
297+
Issue: Shouldn't this be called "normal" instead?
298+
''appearance/none'' makes it sound like the targeted element will disappear.
299+
<dt><dfn>button</dfn>
300+
<dd>The element is rendered with the look and feel of a push button,
301+
similar to the rendering of the HTML <{button}> element.
302+
</dl>
303+
304+
On form elements when the computed value is ''appearance/auto''
305+
and on other elements when the computed value is neither ''appearance/auto'' nor ''appearance/none'',
306+
UAs may disregard some CSS properties
307+
to ensure that the intended appearance is preserved,
308+
or because these property may not be meaningful for the chosen appearance.
309+
However, the following properties must not be disregarded:
310+
<ul>
311+
<li>'appearance'
312+
<li>'display'
313+
<li>'visibility'
314+
<li>'position'
315+
<li>'top'
316+
<li>'right'
317+
<li>'bottom'
318+
<li>'left'
319+
<li>'float'
320+
<li>'clear'
321+
</ul>
322+
323+
Issue: Are there more properties should include in this list?
324+
Should we remove some?
325+
Should whitelist the properties that are ok to ignore instead of
326+
blacklisting those that are not?
327+
Either way, UAs do ignore some properties when rendering form controls,
328+
so this specification should have something to say about this.
329+
330+
All decorative visual aspects of a form control which are not caused by a CSS style rule
331+
must be suppressed when the appearance is changed using 'appearance',
332+
even if the UA's internal representation for this element
333+
was composed of multiple elements or pseudo elements combined together.
334+
For example, <{select}> is often rendered with an arrow on the right side
335+
indicating that the list will be expanded if the element is clicked.
336+
If the computed value of 'appearance' is ''appearance/none'', this
337+
must disappear.
338+
339+
However, the UA must preserve aspects of the form control
340+
which are necessary to operate the control with its original semantics.
341+
This does not include aspects of a control which are merely needed to observe the state the control is in,
342+
only those that are needed for the user to be able to modify the state of the control.
343+
The UA may however give them a different look and feel
344+
as long as it remains possible to operate the control.
345+
For example,
346+
the slider of an <code class="lang-markup">&lt;input type=range></code> is preserved
347+
(or replaced by an equivalent mechanism)
348+
even if 'appearance' is ''appearance/none''
349+
as it would otherwise not be possible to change the value of the range with the mouse.
350+
However, the check mark in an <code class="lang-markup">&lt;input type=checkbox checked></code>
351+
must be suppressed,
352+
as it merely indicates the state the element is in,
353+
which can be styled in different ways using the '':checked'' selector.
354+
355+
Issue: UAs are inconsistent about the preceding two paragraphs.
356+
What is specified here attempts to give some logic
357+
to what is preserved and what is not,
358+
based on the use-cases for 'appearance'.
359+
360+
UAs should include in their User Agent stylesheet style rules
361+
to give form controls a recognizable shape when 'appearance' is ''appearance/none''.
362+
363+
Note: Authors may therefore need to override these UA style rules to get the styling
364+
they intended, possibly by using ''all: unset''.
365+
366+
Issue: This usage of the 'all' property would remove focus indicators
367+
created by the 'outline' property,
368+
which seems undesirable.
369+
Using ''all: default'' would not solve it, as it would fail to remove
370+
the UA styles as intended.
371+
How can we mitigate this?
372+
373+
The behavior and semantics of elements remain defined by the host language,
374+
and are not influenced by this property.
375+
For example, regardless of the computed value of 'appearance':
376+
<ul>
377+
<li>Elements which can be in different states keep this ability,
378+
and the relevant pseudo-classes match as usual.
379+
<li>If a <{select}> element is activated,
380+
the UI to choose one of the associated <{option}> elements is shown
381+
(although it may look different).
382+
<li>Event handlers attached to the element trigger as usual.
383+
</ul>
384+
Conversely, changing the appearance of an element must not cause it
385+
to acquire the semantics, pseudo classes, event handlers, etc
386+
that are typical of the element whose appearance it acquires.
387+
388+
<div class=example>
389+
An author wanting to customize the look and feel of check boxes in HTML could use the following:
390+
<pre><code class="lang-css">
391+
input[type=checkbox] {
392+
appearance: none;
393+
all: unset;
394+
width: 1em;
395+
height: 1em;
396+
display: inline-block;
397+
background: red;
398+
}
399+
input[type=checkbox]:checked {
400+
border-radius: 50%;
401+
background: green;
402+
}
403+
</code></pre>
404+
405+
<code class="lang-markup">&lt;input type="checkbox"></code> would be rendered as
406+
<span style="display: inline-block; width: 1em; height: 1em; background: red;"></span>,
407+
while <code class="lang-markup">&lt;input type="checkbox" checked></code> would be rendered as
408+
<span style="display: inline-block; width: 1em; height: 1em; background: green; border-radius: 50%;"></span>,
409+
and activating (for example by clicking) the element would toggle the state as usual.
410+
</div>
411+
235412
<hr title="Separator from footer">
236413

237414

0 commit comments

Comments
 (0)