You will notice that most forms have boxes around them. This could be done easily using CSS since, as was shown in Chapter 3, the CSS box model supports borders. Because forms requiring boxes around areas is so common, and likely because forms existed before CSS did, HTML has an element for putting content into a box. The tag for this element is fieldset. This tag does a good job of describing it’s purpose but is not the most obvious choice. Using a field set works just like any other div style element.
One of the nice things about using a field set instead of using CSS styles is that it supports having a legend. This is descriptive text that appears in the top-left corner of the box used to describe the fields in that box. While it is possible to get the same effect using CSS, it would require some complexity. To add a legend to a fieldset element, you simply need to use the legend tag inside of that element as shown here:
Finally, you can have nested fieldsets. The form below shows how you can put multiple fieldsets into another fieldset. You can even alter the css of a fieldset to allow them to be side by side as is being done with the radio buttons and checkboxes. This is done by specifying a width for the fieldset style and making sure that the display is inline-block. When we get into CSS layout in Chapter 6, several other ways of easily arranging fieldsets will be possible.
It makes a lot of sense to put related checkboxes and radio buttons into their own fieldsets but this leads to the obvious question about how do we work with checkboxes and radio buttons. That is what we will examine next.
This chapter's summary cheat sheet.
How forms are traditionally used.
How to set up a form in HTML.
Getting text input from the user.
Making your input fields more specific and semantic.
Making forms look more like printed forms.
How to use Checkboxes and Radio buttons.
Using numbers and dates gives your user better GUI controls.
The reset, button, image, color, and file input types.
The select element lets users select options from a drop-down list.
Coming October 20th.
Coming October 27th.
Coming November 3rd.
Coming November 17th.
Coming November 24th.
Coming December 1st.
Coming December 8th.
Coming December 15th.