Skip to content

Commit e9fd206

Browse files
Establish a rule about element overloading (#502)
* Establish a rule about element overloading I'm sure that we could say more, but I think that this is enough. Closes #370. * Add some divs
1 parent efad741 commit e9fd206

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

index.bs

+44
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,50 @@ If the attribute identifies a URL that is auxilliary to the element's purpose, l
11741174

11751175
Note: remember that attributes containing URLs should be represented in IDL as {{USVString}}; see [[#idl-string-types]].
11761176

1177+
<h3 id="html-overloading">Give each HTML element a single purpose</h3>
1178+
1179+
Each HTML element should have a clear purpose.
1180+
Using HTML attributes can modify the semantics of an element,
1181+
but attributes should not fundamentally alter that purpose.
1182+
1183+
Rather than defining elements that can operate in different modes,
1184+
having a separate element for each mode is preferable.
1185+
This simplifies usage for authors.
1186+
1187+
<div class=example>
1188+
The <{input}> element uses a <{input/type}> attribute to switch between
1189+
very different modes.
1190+
Though each of these modes share a common goal of taking user input,
1191+
that is too broad a purpose.
1192+
The semantics of these modes could have been more clearly expressed
1193+
through the use of distinct element names.
1194+
</div>
1195+
1196+
Overloading of semantics on the same element
1197+
through the use of attributes could be used to select
1198+
between different behavior.
1199+
This only makes sense where the purpose remains the same
1200+
for any value of the attributes.
1201+
1202+
<div class=example>
1203+
The <{textarea}> element and an <{input}> element with a <{input/type}> of `"text"`
1204+
could have used the same element as the differences between these is not material.
1205+
</div>
1206+
1207+
Potential counterexamples include overspecialization
1208+
and elements that rely on context to establish their semantics.
1209+
1210+
<div class=example>
1211+
The now-deprecated <{acronym}> element is duplicative of the <{abbr}> element
1212+
and therefore overspecialization.
1213+
</div>
1214+
1215+
<div class=example>
1216+
The <{source}> element can have distinct purposes depending on context.
1217+
A <{source}> element is not standalone; it's semantics are determined by its parent.
1218+
</div>
1219+
1220+
11771221
<h2 id="css">Cascading Style Sheets (CSS)</h2>
11781222

11791223
This section details design principles for features which are exposed via CSS.

0 commit comments

Comments
 (0)