So, I have done a bit of research on forms. Trying to make them as happy as possible for design, accessibility and usability. It seems that, as important as forms are to the web, there would be some agreement or idea and the best way to accomplish this. There may be, but I didn’t find it, so I created one. This is an HTML and CSS contract to make the forms happy.
So, here is the basic HTML example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <div class="form"> <fieldset> <legend>Main Title</legend> <ol class="formlist"> <li> <label>Label:</label> <div> <asp:textbox runat="server" id="txtExample" ></asp:textbox> </div> <hr /> </li> <li class="submitcontainer"> <asp:button runat="server" id="btnExample" onClick="btnExample_OnClick" text="Submit" /> </li> </ol> </fieldset> </div> |
These examples are using C# so the div tag is a div class=”form” instead of just a form tag. This is because C# / asp.net uses a huge form tag the covers the whole page. I am not commenting on that at the moment maybe later.
and here is how it would render as plain HTML
There are several simple advantages to this form layout. First is the accessibility features. This taps into the screen readers default handling of fieldsets and ols to make navigation easier for them. It also has all the markup necessary, with out extras, to style up the form pretty much how ever you want it. Using the div to separate the label with the control is that you have room to do what ever you need to for the control including placing lots of controls and even embedded forms without any extra work.
There is also a way to add errors and info to the form very easily.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <div class="form"> <fieldset> <legend>Main Title</legend> <ol class="formlist"> <asp:panel runat="server" id="pnlExample"> <li> <label class="none"></label> <asp:panel runat="server" id="pnlErrorsExample" CssClass="errors"> <!-- the spans or asp:labels may be added dynamically by using this panel --> <span class="error">This is a global error message that may be displayed on error that would say, hey this form has these errors: </span> <span class="error">You need to type something in the TextBox</span> <span class="error">You need to click the submit button</span> </asp:panel> </li> </asp:panel> <li> <label>Label: <asp:RequiredFieldValidator ID="rfvExample" runat="server" ErrorMessage="This is required" Display="Dynamic" ControlToValidate="txtExample" CssClass="error"> </asp:RequiredFieldValidator> </label> <div> <div class="information"> <span class="info">This describes the example here.</span> </div> <asp:textbox runat="server" id="txtExample" ></asp:textbox> </div> <hr /> </li> <li class="submitcontainer"> <asp:button runat="server" id="btnExample" onClick="btnExample_OnClick" text="Submit" /> </li> </ol> </fieldset> </div> |
Again, these examples are for use with asp.net controls, but you can easily use this for any language by replacing the and here is how this would look with no CSS: what is good about the way that these are built is that it is very accessibility friendly. The global error message is at the front of the form, so screen readers will get to that first. Next the errors are included in the labels of the controls, so as the screen reader introduces what the control is it will also read what errors are related to the controls so the user can know what needs to be fixed without navigating around to find it. Now lets style these up. I am going to use the theme that I have built for the administration section of NAU Extended campuses but the styles are very customizable and interchangeable. I am not going to pull apart everything in the css file, but I do want to mention that it is built to include most possible scenarios including columns. Here is the basic form and the error/info form with the styles in place. You can view source and use as you would like. Like I said this design is what is used in the Admin section of NAU EC. This way of coding up the form is extreamly customizable which is one of the reasons why it is so good. So Code, Design, and Enjoy.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
margin: 0 0 1em 0;
border: 1px solid #DDF;
}
.form fieldset legend {
margin: 0 0 .5em 0;
padding: 2px .5em 0 .5em;
color: #036;
background: transparent;
font-size: 21px;
font-family: "Times New Roman", Times, serif;
}
.form ol.formlist {
padding: 0;
margin: 0;
font-size: 12px;
font-family: "Times New Roman", Times, serif;
}
.form .col {
float:left;
width: 49%;
min-width: 350px;
border-right: 1px solid #ccc;
padding-right: 15px;
}
.form .col:last-child {
border-right: none;
padding-right: 0;
}
.form li {
list-style: none;
padding: 0;
margin: 4px 2px 0 10px;
clear: both;
padding-top: 2px;
}
.form li > label {
display: block;
width: 120px;
float: left;
clear: left;
margin: 0 15px 0 0;
text-align: right;
}
.form li > label.none {
width: 0;
margin: 0;
}
.form li hr.none {
border: none;
border-bottom: 1px solid transparent;
background: transparent;
}
.form li > label span {
display: block;
}
.form li > label span[style*="inline"] {
display: block !important;
}
.form li > div {
margin: 0 0 0 140px;
padding: 0;
}
.form li > label.none + div {
margin: 0;
}
.form hr {
margin-top: 2px;
clear: both;
border: none;
border-top: 1px solid #CEE6F7;
}
.form ol > li:last-child > hr {
border: none;
border-bottom: 1px solid transparent;
}
.form .formlist textarea, .form input, .form select {
margin: 0 0 5px 0;
}
.form input[type="textbox"], .form select, .form textbox {
min-width: 100px;
}
.form .block {
display: block;
}
.form .errors {
border: 1px solid #903;
background: #F5D8D9;
padding: 5px;
margin-bottom: 5px;
}
.form .error {
font-size: 11px;
color: #903 !important;
text-align: right;
margin: 0 0 5px 0;
display: block;
}
.form .errors .error {
text-align: left;
}
.form .information {
border: 1px solid #090;
background: #ECFFD9;
padding: 5px;
margin-bottom: 5px;
}
.form .info {
font-size: 11px;
color: #030;
text-align: right;
margin: 0 0 5px 0;
display: block;
}
.form .submitcontainer {
margin: 25px 0 35px 164px;
padding: 0;
border: none;
}
.form fieldset .submitcontainer {
margin: 15px 0 35px 149px;
}
The CSS file is also built to the standard shown in the post Css Management Standard.

