- Use soft-tabs with a two (or four) space indent. Spaces are the only way to guarantee code renders the same in any person’s environment.
- Paragraphs of text should always be placed in a
tag.
- Break apart paragraphs using additional
tags (NOT
). - Items in list form should always be in
- Even though quotes around attributes is optional, always put quotes around attributes for readability.
- Use semantic HTML elements to structure the page, don't use
everywhere.
,
, or
. Never use a set of
or
.
- Every form input that has text attached must utilize a
tag. Especially radio or checkbox elements.
- Missing label elements will cause errors on accessibility testing.
- Labels can be hidden for design but are necessary for accessibility. Do not rely on placeholder text to label an input.
- Tab index should be set appropriately if page elements change common sense flow. Always try tabbing through your page at least once to see what happens and if you can access all links, menus, form inputs, and buttons.
- Inputs should have both
id
andname
- Input
id
andname
should be the same value for syncing front end to back end - Form element itself can have both
id
andname
- Inputs can have multiple
label
tags- Take advantage of this to make additional text more semantic:
Password: *Your password must be at least 8 characters long.
- Since so many labels are styled separately from their inputs (or hidden), don't nest the input inside of its label:
// Yes do this Password: // Don't do this Password:
Fieldset
is quite useful for grouping form elements in a semantic manner, especially if similar input types are on the same screen- Include a with , even if is it hidden from view. Screen readers can use it to help users.
Login Password: Sign Up Password:
References: