Avoid using ID attributes in preference to classes.
ID attributes have to be unique on the document level. To avoid accidentaly having multiple elements with the same ID, we prefer to use class attributes. There are two situations where we still need an ID attribute: - Connecting <label> elements to the associated input element using the 'for' attribute - Connecting description of an element with the 'aria-describedby' attribute. In the first case, we can often wrap the associated input inside the <label> tag, so that we don't need IDs, although in some cases that is not possible because it breaks the layout. In cases when we still need to use ID attributes, we append a random string to ensure uniqueness.
Showing
Please
register
or
sign in
to comment