@@ -273,15 +273,15 @@ and allows users to choose their own font and font size without causing text to
273
273
<h3 id="leave-the-web-better">Leave the web better than you found it</h3>
274
274
275
275
As you add new capabilities to the web platform, do so in a way that improves
276
- the overall platform, for example its security or privacy vulnerabilities, or accessibility characteristics.
277
- The existence of a defect in one part of the platform must not be used as a license
278
- for adding or extending such defect into new capabilities and thereby further decreasing
279
- the overall platform quality. Where possible, build new web capabilities that
276
+ the overall platform, for example its security or privacy vulnerabilities, or accessibility characteristics.
277
+ The existence of a defect in one part of the platform must not be used as a license
278
+ for adding or extending such defect into new capabilities and thereby further decreasing
279
+ the overall platform quality. Where possible, build new web capabilities that
280
280
improve the overall platform quality.
281
281
282
- Parts of the web platform evolve independently.
283
- Issues that are present with a certain web technology now may be fixed in a subsequent iteration.
284
- Duplicating these issues makes fixing them more difficult.
282
+ Parts of the web platform evolve independently.
283
+ Issues that are present with a certain web technology now may be fixed in a subsequent iteration.
284
+ Duplicating these issues makes fixing them more difficult.
285
285
By adhering to this principle we can make sure overall platform quality improves over time.
286
286
<h2 id="api-across-languages">API Design Across Languages</h2>
287
287
@@ -297,7 +297,7 @@ although they may be harder to find.
297
297
Simpler features are easier for user agents to implement and test,
298
298
more likely to be interoperable,
299
299
and easier for authors to understand.
300
- It is especially important to design your feature so that
300
+ It is especially important to design your feature so that
301
301
the most common use cases are easy to accomplish.
302
302
303
303
Make sure that your <a href="#priority-of-constituencies">user needs</a>
@@ -316,7 +316,7 @@ commonality and complexity are not always correlated.
316
316
<div class=example>
317
317
Sanitizing HTML to prevent XSS attacks is a complex process
318
318
that requires extensive security knowledge,
319
- however the [Sanitizer API] (https://wicg.github.io/sanitizer-api/) provides a shortcut for this common use case.
319
+ however the [Sanitizer API] (https://wicg.github.io/sanitizer-api/) provides a shortcut for this common use case.
320
320
It also permits simpler types of filtering, but with more configuration.
321
321
</div>
322
322
@@ -973,6 +973,70 @@ the functionality you are adding is **not** similar to that of the existing attr
973
973
This is an antipattern; one of these groups of attributes should have had a different name.
974
974
</div>
975
975
976
+ <h3 id="html-lists">Use space-separated attributes for short lists of values, separate elements for longer lists</h3>
977
+ <!-- https://github.com/w3ctag/design-principles/issues/277 -->
978
+
979
+ When specifying metadata about an element that can be a list of values,
980
+ common practice is to use a space-separated list and expose it as a {{DOMTokenList}} .
981
+
982
+ <div class=example>
983
+
984
+ The <{global/class}> attribute on elements takes a space-separated list of class names.
985
+ {{Element/classList}} is a {{DOMTokenList}} that allows authors to add and remove class names.
986
+
987
+ </div>
988
+
989
+ <div class=example>
990
+
991
+ The <{iframe/sandbox}> attribute takes a space-separated list of sandbox flags.
992
+ `iframe.sandbox` is a {{DOMTokenList}} that allows authors to add and remove sandbox flags.
993
+
994
+ </div>
995
+
996
+ Consistency with other parts of the Web Platform is important,
997
+ even if this means using another character to separate values.
998
+
999
+ <div class=example>
1000
+
1001
+ The <{input/accept}> attribute is a comma-separated list of values,
1002
+ because it needs to match the syntax of the `Accept` HTTP header. (See [guidance on HTTP headers] (#new-http-header-syntax))
1003
+
1004
+ </div>
1005
+
1006
+ Regardless of syntax, attributes should only be used for short lists of values.
1007
+ For longer lists, embedding the entire list in an attribute is discouraged.
1008
+ Instead, current practice is to use separate elements to represent the list items (and any metadata about them).
1009
+ These elements could either be children of the element in question, or linked through an attribute.
1010
+
1011
+ <div class=example>
1012
+
1013
+ The list of values for the <{select}> element is provided as a series of <{option}> element children.
1014
+ However, when providing a list of recommended values for an <{input}> element, a separate element is used (<{datalist}> ),
1015
+ linked through a <{input/list}> attribute.
1016
+
1017
+ </div>
1018
+
1019
+ <div class=example>
1020
+
1021
+ The list of media sources for a <{video}> or <{audio}> element is provided as a series of <{source}> element children.
1022
+
1023
+ </div>
1024
+
1025
+ In rare instances, other tradeoffs are necessary.
1026
+
1027
+ <div class=example>
1028
+
1029
+ The <{img/srcset}> attribute allows for a comma-separated list of image candidate strings.
1030
+ This syntax was chosen over a list of child elements to avoid verbosity
1031
+ and because the <{img}> element is an empty element that does not permit child elements.
1032
+ A space-separated syntax would not have been possible, as each list item includes multiple values.
1033
+
1034
+ <!--
1035
+ TODO: link to the "microsyntaxes are usually bad" principle once it's been written.
1036
+ https://github.com/w3ctag/design-principles/issues/213
1037
+ -->
1038
+ </div>
1039
+
976
1040
<h3 id="avoid-html-parser-blocking">Do not pause the HTML parser</h3>
977
1041
978
1042
Ensure that your design does not require HTML parser to pause to handle external resources.
0 commit comments