Lecture 2 Pre-reading

Press right arrow

Instructions

Hierarchy

Inline elements

Lists

Hyperlinks

Multimedia

Figures

Tables

Generic containers

Disclosure widget

Interactivity

Input fields

  • The input element can generate a wide variety of form controls, differentiated by the type attribute. If no type attribute is present, type="text" is assumed.
  • The following only applies to textual inputs (text, url, email, tel etc):
    • The placeholder attribute shows placeholder text when the field is empty. This is available on textarea too.
    • The pattern attribute allows you to restrict input. This does not currently work on textareas, but there are efforts to make it so.
  • In numerical and date inputs (number, range, date, time etc), the min and max attributes allow you to restrict the range of input.
  • On number and range inputs, you can use the step attribute to control the increment (1 by default).

Multiple choices

  • Group radio buttons via the name attribute to make them mutually exclusive.
  • Set checked state on checkbox and radio buttons via the checked attribute
  • label elements are very useful for all form controls, but especially checkboxes and radios as they increase the target area!
  • Depending on the number of options, different form controls are more appropriate for usability:
    • For < 4 options, prefer radios if you have space (sometimes avoiding clutter is more important, e.g. when part of a template that is multiplied), as they are the most efficient.
    • Between 5-20 options, select menus are ideal
    • For longer than 20 options, search time for select menus becomes longer than typing the first few characters. In those cases, use input with datalist for autocomplete)
  • The fieldset element is useful for grouping together related form controls.

Buttons & Forms

  • The button element creates buttons.
  • These buttons don’t do anything by themselves, but you can make them useful via JavaScript or form elements.
  • The action attribute of form elements controls which file will receive the submission. By default it's the current file.
  • What’s submitted? Only elements that are both enabled and have a name attribute.
  • target="_blank" works here too, to submit the form in a new tab

HTML resources

Looking for help online?

How to avoid bad/outdated resources