Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it acceptable to use tables for forms? Or is it still more correct to use divs?

I'm wondering whether it's acceptable to use tables for forms.

Strictly speaking, name/value pairs are tabular data, aren't they? And a form is just a user customisable set of name/value pairs. So is it right to use tables in this case? Or should I use divs styled with CSS?

like image 321
Eric Avatar asked Sep 08 '09 18:09

Eric


People also ask

Should I use tables for forms?

Using tables for a form is a big no-no. There is absolutely no need to put a form in tables. Both aren't correct.

Can you have tables in a form?

You can have an entire table inside a form. You can have a form inside a table cell. You cannot have part of a table inside a form. Use one form around the entire table.

Why do professional designers no longer use tables for layout?

The World Wide Web Consortium (W3C®) discourages use of tables for layout because they are striving for a web in which content and structure are completely separate from presentation.

Do people still use tables in HTML?

The table element is still the correct way to provide tabular data in a semantically correct way in HTML. So if you use it semantically correct it is fine and not outdated per se.


2 Answers

Try fieldsets

I prefer to break up the fields into logical <fieldset>s with one <legend> each, because:

  • The code is less cluttered
  • The default formatting is user-friendly (I especially like how the legend displays)
  • It's easy to style with CSS

Here's a code example. Note that the labels' for attribute lets you click that label to move focus to the input specified (it matches the id attribute).

<form>   <fieldset>     <legend>Wombat Statistics</legend>     <ol>       <li>         <label for="punchstrength">Punch Strength</label>         <input id="punchstrength" name="punchstrength" />       </li>       <li>         <label for="beverage">Favorite Beverage</label>         <input id="beverage" name="beverage" />       </li>     </ol>   </fieldset>   <fieldset>     <legend>Questions That Are Too Personal</legend>     <ol>       <li>         <label for="creditcard">What is your credit card number?</label>         <input id="creditcard" name="creditcard" />       </li>       <li>         <label for="gullibility">Did you actually fill that in?</label>         <input id="gullibility" name="gullibility" />       </li>     </ol>   </fieldset> </form> 

For a basic layout, you can use something like:

label, input, textarea, select {    display: inline-block; vertical-align: top; width: 30%;  } 

See this article for a more in-depth tutorial.

like image 158
Nathan Long Avatar answered Sep 20 '22 05:09

Nathan Long


Both are correct.

I preffer using some div/li, as that allows me to make some different layouts, but tables for forms are not frowned upon.

Actually, by default, Django gives you table formated forms.

like image 24
Esteban Küber Avatar answered Sep 23 '22 05:09

Esteban Küber