ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web

Create HTML form using lists and css/html

Updated on May 4, 2016

Why html lists to create html forms?

With this post i will take you through how to create html forms using HTML lists. It will be a form a system may use for data collection. For example it can be a registration form, contact form, login form, customer registration form or sales order form etc. It can be one of many forms that we have come across day to day browsing.

A sample html form

a sample html form
a sample html form | Source

Web developers use various methods to code and apply design to html forms. HTML coders cut-up photoshop designs into tiny images and code them into css/xhtml layouts, Many web developers prefer using standard html tags to code html form. This post will demonstrate how to use HTML list with greater effect on building your html form layouts.

Power of html lists are huge, I would say lists can even replace DIVs. Some html coders think html lists are there only to show bullet point content and menus, Wrong assumption I guess. Some coders even find the default behavior of html lists are different to than other html tags. This makes list bit hard to code in css.

Let us look the power of HTML Lists. Lists give more control in html code and in return lists gives less troubles when it comes to browser compatibility. You need to learn default behaviors of html lists before you using it for coding, Such default properties are bullet pattern, margin and padding. Before you use html list for regular html coding it requires you to get ride of these default properties using css.

Most html coders prefer to use DIVs and fieldset html tags to create html forms for data capturing.

But lists will furnish you more control on coding this kind of HTML form layouts, Lists acts like a replacement for html tables.At WeCodeYourSite we do lot of research into this and so far it is real successful. One of the success was using html lists to create html forms.

By using HTML Lists you can code html forms very quickly like in html tables. Once you make list to behave like html tables it is just a matter of copy & paste, like we did html tables.

Let’s dig into how to code a real world html form layout using the code snippet below,

 <input id="txtDiscount" type="text" /></li>
 <li>Address :</li>
 <input id="txtAmount" type="text" /></li>
 <input id="Text1" type="text" /></li>
 <input id="Text2" type="text" /></li>
 <input id="txtDisAmt" type="text" /></li>
 <input id="txtNetAmt" type="text" /></li>
 <textarea id="Text3" rows="5" cols="30" ></textarea></li>
 <input id="Submit1" type="submit" value="Send" /></li>

How to arrange list to create a html form?

The above html code snippet will produce a simple registration form, a very basic one.The html code is simple and strait forward. As you can notice how simple lists in html code, Let us look how this code operate with the browser. As we all know list elements(<li> tags) are surrounded by another html tag(<ul> tag). This tag will be acting as a container for all the list items. It is something similar to field-set tag. As you can recall a registration from you have use before, it had labels to say name of the input and on the other site the input text box or drop down is placed to capture the data input. This layout something similar to a two column table. So each row need two cells, with lists we need two list items to create the required row structure. As you can notice in above code I have placed the labels in one list item and followed with a the input control. Now html structure in place let us look at the css styles which will make the above html code professional html form.

ul{list-style-type: none;float:left;width:400px;}

ul li{float:left;width:150px;margin-top:10px;}

ul li.input{width:250px;}

Look how simple the css/xhtml code.

Let me explain what each css/xhtml style does.

As we all aware that the unordered list(ul) tag will be the parent control tag, it will going to grip all the list items together.

By using style property value none for list style type we can take away bullets that comes default for unordered lists or ordered list(the other counterpart list).

Remember both unordered list(ul) plus ordered list(ol) tags by default you has set to 20 pixel margin and 20px padding. For some browsers it acts as padding for some it acts as margin.

If you don’t need default padding and margin, you be able to remove default margin and padding by setting to 0 pixel for both under unordered list style property.

This default margin padding of ordered lists Confuse most of css coders, at the beginning of their career.

Any html form has a defined width. In this case form container will be the ul tag. By setting a width to it we can set the form width. The float property is necessary to keep the floated list items within the same row together, list item top margin will keep the gap between form controls.

Here I have used an ordinary width for the list item that is the width of the form labels.

Last css/xhtml style is to override the default width of the list item to accommodate more space to input controls.

If you look at overall html and css it is very simple and easy maintain. You can find the complete sample of how to create html forms using lists


    0 of 8192 characters used
    Post Comment

    • nnjiru profile image

      nnjiru 4 years ago

      Good tutorial. To see about calculating using form and JavaScript follow the link;

    • wecode profile image

      wecode 4 years ago from Australia

      thx for reading....! but sorry mate this is my way thx for u'r suggestions

    • profile image

      mtt 4 years ago

      I read, and it is really crappy and dirty way to do it.

      You already have labels and input tags, why the hell would you add li tag over it ?

      I gave a correct way to do it on my previous comment.

    • wecode profile image

      wecode 4 years ago from Australia

      Please read the code carefully .... it uses two li tags. One for the label text and the other to hold the input box.... the article is about how to use ul li tags to build html form not labels.....

    • profile image

      mtt 4 years ago

      Omg, it's really crappy !

      You don't even use labels ! and using 1 li by elements is against the lists semantic !

      a good way should be :

      [li][label for="foo"]foo[/label][input type="text" id="foo"][/input][/li]

      And this thing is in first google page...