Best way to mark up Forms?
by Megan, Mon, 2007-07-23 13:48
a list
100% (4 votes)
a table
0% (0 votes)
paragraphs
0% (0 votes)
divs
0% (0 votes)
something else
0% (0 votes)
Total votes: 4
by Megan, Mon, 2007-07-23 13:48
Megan posted this at 13:30 — 23rd July 2007.
She has: 11,421 posts
Joined: Jun 1999
Eh, I've seen other things on the W3C site that weren't entirely done correctly. I believe they also have a table in the form example in the spec. I'd be more likely to look at what, say Eric Meyer does. Maybe we can ask on css-discuss or something like that. I'll put up a poll here and then when I have time I'll email around and see what some of the experts say.
If you were to do it in a table, I'm not sure you would use the and a or just one or the other...
I read that usability article too (wasn't it linked here earlier??) - I wouldn't trust usability experts as authorities on HTML code either. I don't have time to read the article again. Do they specifically recommend tables or are you just extending that from the way the examples are marked up??
Megan
Connect with us on Facebook!
teammatt3 posted this at 23:26 — 20th July 2007.
He has: 2,102 posts
Joined: Sep 2003
The W3C uses tables for forms. See for yourself. They're the standards organization, follow their example. Use tables!
andy206uk posted this at 11:08 — 21st July 2007.
He has: 1,758 posts
Joined: Jul 2002
Stop being dirty... we're civilised people around here, the guys at the W3 are clearly Neanderthals!
Actually, I was reading an article the other way about the best way to lay out tables to ensure usability and the outcome was basically a table layout!
Link: http://www.uie.com/articles/web_forms/
I got the paragraph definition from Google by typing "define: paragraph", but it was one of many results and certainly not the only definition, I took the one that most suited my argument
I totally agree that this is a circular argument that nobody can win. Although on the basis that the W3 uses tables AND it's better for usability maybe we should be using tables?
In fact... if you look at excel a typical screen is effectively just a big form, but at the same time, it's also a table...
I think we should come to some kind of agreement about this between us, take a vote (maybe via APC?) and start spreading the word
So what would be the best table layout? Something like this?
<table>
<tr>
<th><label for="name">Name</label></th>
<td><input type="text" id="name" name="name" value="" /></td>
</tr>
<tr>
<th><label for="email">Email</label></th>
<td><input type="text" id="email" name="email" value="" /></td>
</tr>
</table>
Andy
Megan posted this at 17:09 — 20th July 2007.
She has: 11,421 posts
Joined: Jun 1999
Where did you get that definition? I see your point though. I know the W3C has been talking about expanding the definition of "paragraph" so they don't have to invent other tags for other types of text. I also read that the W3C is/was considering replacing with because of the over-use of div's. Division, section - shouldn't be necessary here but neither should the paragraph/list tags.
I definitely agree that a form is not a table. I also agree that it shouldn't have to be a paragraph or a list. We're sort of talking in circles here though It shouldn't need extra markup > but it does need extra markup > so what is it then? > not sure, could be div, paragraph, or list > but it's not really any of those > it shouldn't need extra markup > but it does need extra markup etc. etc.
Even by that definition, I would say that a form is as much a list of items as it is "a distinct subdivisions of a text intended to separate ideas". Possibly moreso.
I guess this one comes down to whatever you think makes the most sense.
Megan
Connect with us on Facebook!
andy206uk posted this at 16:22 — 20th July 2007.
He has: 1,758 posts
Joined: Jul 2002
I just don't see a form as a list...
One definition of a paragraph is:
So by that definition doesn't the label for the form qualify as a paragraph?
I've had debates with people about this before and usually someone all suggests a table for form layout to which I kind of agree but I hate the limitations of tables for layout. In all honesty, I don't think there is a right answer when it comes to laying out forms if you require it to be 100% semantically correct.
Simply put a form isn't a list or a paragraph, it certainly isn't a proper table either.
I suppose the only correct markup to use is a div which is simply a container for information and nothing more but that lacks semantics...
Andy
Megan posted this at 15:27 — 20th July 2007.
She has: 11,421 posts
Joined: Jun 1999
Fieldsets should really be used for sets within the form. So a whole personal information block would have a fieldset around it. Using them like this would preclude you from using them for larger blocks.
Why would you prefer paragraphs over lists?
Megan
Connect with us on Facebook!
andy206uk posted this at 14:14 — 20th July 2007.
He has: 1,758 posts
Joined: Jul 2002
Lol... stupid IE!
How about this?
<form>
<fieldset>
<label for="name">Name</label>
<input type="text" id="name" name="name" value="" />
</fieldset>
<fieldset>
<label for="email">Email</label>
<input type="text" id="email" name="email" value="" />
</fieldset>
</form>
It could be a total abuse of the fieldset tag, but surely it's more relevant than 's?
Personally, I'll be sticking to my paragraph tags for now.
Andy
Megan posted this at 13:53 — 20th July 2007.
She has: 11,421 posts
Joined: Jun 1999
Andy, you might want to check that in IE.
andy206uk posted this at 13:49 — 20th July 2007.
He has: 1,758 posts
Joined: Jul 2002
Aside from the 's I don't use any structural markup. I just use CSS floats and what not (if I want the input and label on separate lines, I use CSS to make the label a block level element).
I understand that the text isn't a paragraph, I would just prefer to use something that has some meaning rather than something with no meaning like a .
I suppose you could use an unordered list like you suggest, it's just a matter of preference.
Just out of interest... would this be acceptable?
<form>
<label for="name">Name</label>
<input type="text" id="name" name="name" value="" />
<label for="email">Email</label>
<input type="text" id="email" name="email" value="" />
</form>
I've just styled that code with css and got it looking like this which is pretty much my standard form layout. Unless you wanted background colours for each row of the form (full width that is), I don't see why you would need anything around the label/input parts.
Andy
kazimmerman posted this at 13:26 — 10th July 2007.
He has: 698 posts
Joined: Jul 2005
I've been searching around the web since this topic came up, and it seems that the most prominent way to mark up forms without tables (of course) and DIVs is to use a list and labels. Here's my curiosity. If you were to use this list format, would you still use it for vertical forms? If so, are the label and the input each a list item, or should they be connected in some way?
Kurtis
Megan posted this at 13:12 — 10th July 2007.
She has: 11,421 posts
Joined: Jun 1999
Well, as I said, a form input is definitely not a paragraph. Ideally we would use option 6 and not have extra structual mark-up in there at all. Option 4 would be the ideal because there is no extra structural mark-up. Semantically it's not needed. However, it's really difficult to lay out forms like that with CSS, so you have to add some structure around them.
Then back to the question: if you have to add structural mark-up, what do you use? Do you just have a line break there? are to be used as a last resort IMO. They don't really have structural meaning and are only necessary to work around some other problem. Now we have to look at the other structural options. A form input is definitely not a paragraph or a table. Is it a list? That sounds most sensical to me.
Is it a definition list or a regular list with the label in it? I sort of think that having the makes the definition mark-up redundant. But, on the other hand, these are name/value pairs so in that sense the definition list makes sense.
So the advantage is proper structural mark-up and separation of presentation from mark-up
Megan
Connect with us on Facebook!
demonhale posted this at 06:17 — 10th July 2007.
He has: 3,278 posts
Joined: May 2005
I also use to wrap, to break and no labels, just form elements, then use CSS to make it look pretty... What are the advantages of using list or options 5 and 6 for example?
webwiz posted this at 20:09 — 9th July 2007.
He has: 629 posts
Joined: May 2007
Arguably, forms are the most contentious and difficult elements of web design. I am looking forward to a new book, to be published next winter: "Web Form Design Best Practices".
In addition to a couple of resources on that book announcement, the author has written an article on the subject. Hope these help.
Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;
andy206uk posted this at 19:58 — 9th July 2007.
He has: 1,758 posts
Joined: Jul 2002
I use:
<p>
<label for="name">Name</label>
<input type="text" id="name" name="name" value="" />
</p>
<p>
<label for="email">Email</label>
<input type="text" id="email" name="email" value="" />
</p>
You can then style this in a number of ways using CSS depending on what you are going for and it works with almost all traditional form layouts.
Andy
Megan posted this at 20:31 — 9th July 2007.
She has: 11,421 posts
Joined: Jun 1999
That's interesting - you're saying that a form input is a paragraph? I'd say that a form is as much a paragraph as it is a table (it's not). More like a list if forced to choose
David - that's the article i was referring to in my last post! Thanks for linking it
Megan
Connect with us on Facebook!
teammatt3 posted this at 21:01 — 6th July 2007.
He has: 2,102 posts
Joined: Sep 2003
Good topic. I've been doing a lot of forms too and I use option 4 (never knew there were so many ways!).
I've been through a dozen of those tutorials about making the forms structured like tables but using CSS, it's just too much work, and too much excess markup. On simple forms I'll use CSS, but tables take on the big forms and yes, I do know that the CSS nazis will come after me for it, but ya gotta do what ya gotta do.
How do you usually layout your forms?
Fieldname inputbox
or
Fieldname
Inputbox?
kazimmerman posted this at 21:57 — 9th July 2007.
He has: 698 posts
Joined: Jul 2005
I think there are so many different types of forms, and each one may require a different layout. I think with smaller forms, the vertical layout is my choice, because I would rather have a small square of a form than a wide rectangle of a form.
e.g.
Username:
__________
Password:
__________
as opposed to
Username: __________
Password: __________
However, with longer forms that are basically a whole page (contact forms, registration forms, ordering forms for an online store), I think the side-by-side format would be most desirable.
The whole discussion is quite a doozy.
Kurtis
pr0gr4mm3r posted this at 18:40 — 6th July 2007.
He has: 1,502 posts
Joined: Sep 2006
If you don't want to use break tags, then you can put each one in a div tag.
Megan posted this at 17:31 — 7th July 2007.
She has: 11,421 posts
Joined: Jun 1999
An extra div would be almost as bad as the - no structural meaning. I think the lists are a much better solution here. If you have to put extra mark-up in there to help with the formatting it makes most sense to use a list IMO. The only question in my mind is whether it would be a regular list or a definition list.
For layout - I saw an article recently arguing that the label on top format is more readable. I sort of think it makes more sense to go side-by-side. It depends on the form though. I usually do side-by-side for shorter inputs.
Megan
Connect with us on Facebook!
Megan posted this at 18:35 — 6th July 2007.
She has: 11,421 posts
Joined: Jun 1999
Actually, I couldn't find this on a search so that's one of the reasons I posted it.
Labels are supported (well, they display stuff anyway). It's a good way to semantically connect elements to their labels
pr0grammr - I'm working on that positioning. Watch for article on APC.
Megan
Connect with us on Facebook!
kb posted this at 18:31 — 6th July 2007.
He has: 1,380 posts
Joined: Feb 2002
(Aren't you guys [Megan/JeevesBond] married? So couldn't you, I don't know.... TALK?)
Anyways...
Why the focus on labels and things?
None of that really matters and/or is supported at the moment, and isn't foreseen to be so for a few years. I personally just stick to the normal form stuff, using the inputs, selects, etc. as needed, but I don't bother with labeling anything other than attaching an id on the elements.
pr0gr4mm3r posted this at 18:24 — 6th July 2007.
He has: 1,502 posts
Joined: Sep 2006
I use this layout for all my web forms, but if this is just a multiple choice question, I would choose 3.
As for another suggestion, I would add the following code to the "#contentbox div.tooltip .helptext" block, so the text floats to the right and not bump down the entire form.
position: absolute;
left: 30px;
top: -20px;
Megan posted this at 18:38 — 6th July 2007.
She has: 11,421 posts
Joined: Jun 1999
This would be Option 6:
<label for="element1">This is the label</label><input type="text" id="element1" /><br />
<label for="element2">This is the label</label><input type="text" id="element2" /><br />
Almost the same as my Option 4, but with line breaks in to clear each set of inputs. I prefer not to use 's unless absolutely necessary (separating presenation from structure and all that).
Megan
Connect with us on Facebook!
JeevesBond posted this at 17:03 — 6th July 2007.
He has: 3,956 posts
Joined: Jun 2002
Option 3 is out straight away (you probably already know this, but wanted to provide the option). It's semantically incorrect to use a list to label form elements. That's what the [incode]label[/incode] tag is for.
Option 4 is the ideal, but not always practical as you may need extra markup for styling etc.
Option 2 would be what I'd fall back on if requiring extra markup. It's a good choice because--as you said--a definition list is for marking up name/value pairs.
a Padded Cell our articles site!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.