Is it ok to put elements like <h2> inside <form> tags? I want the form to have a heading and would also like to give some margins in general to the whole form. I could therefore set an id to the form and apply the margins to that id. Else to exclude the <h2> from the form I would create a generic div just outside the form, and apply margins to that, and therefore also put the h2 outside the <form>. Which is best?
I’m afraid to say, as you’ll probably tell me I’ve wasted my money:
What book?
Thanks, will do. I got a book recently, but haven’t delved very far in yet. Keep getting unstracted.
I would not put any non-form elements inside a form. I would use the generic wrapping div.
One reason is that many of the more popular screen readers have a Forms Mode. Some go automatically into Forms Mode (which lets you fill in the form) and there only form controls are read out. That means headers, instructions, and questions who are not inside labels or legends are missed. I would not count on people first listening through in regular mode to hear instructions and then go back and go to Forms Mode to fill it in… we’re lazy, we don’t want to read something twice.
I put all my headers and instructions outside forms, with the exception of help text (which, if it’s inside a label, can be found by a reader in Forms Mode). I have one huge monster form that unfortunately has headers inside, but to compensate I added titles to the inputs (previous version of the form used headers as Main Questions). But ideally it would be totally rewritten.
Read Gez Lemon’s bloggitty and grab a copy of the JAWS demo (40 minutes) for Winblows and play around.
I still haven’t gotten NVDA/Win (a free reader) even though I should. Each reader’s like a browser: has its own quirks.
Both are fine, so far as I know. You can certainly put elements like h2 inside the form element. But another option is to use a fieldset within the form, and make the title with the <legend> element. Here’s more info: http://reference.sitepoint.com/html/fieldset
Worth knowing about the option, anyway.
Wow, good point. I SO need to get on with learning more about accessibility.