HTML CSS Field Layout

Posted on


I’ve had some help designing my field boxes and I was hoping to get feedback on the code. The fields will increase in complexity which is why I thought to structure it this way (image upload fields, textbox with WYSIWYG controls etc.


.error { height: 27px; background-color: red; margin-bottom: 4px;} 
.lft { float: left; }
ul, li { list-style-type: none; vertical-align:middle; }
.ts3 { font-size: 15px; }
.dc3 { background-color: #808080; }
.tc5 { color: #333333;}
.p4 { padding: 4px; }
.r2 { border-radius: 2px; -moz-border-radius: 2px; -webkit-border-radius: 2px; }
.r6 { border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px; }
.field { line-height:27px; font-family:arial, sans-serif; border-color: #d9d9d9; border-top:solid 1px #c0c0c0; }
.fieldwrapper{ padding: 0 5px 0 0; overflow: hidden;}
label{width:200px; display:inline-block; float:left}​


    <li >
<div class="r6 dc3 ts2 p4">
    <div class="error r6">Error!</div>
<label field_id="None" for="sender">Sender email address</label>
<div class="fieldwrapper">
<input class="field r2" placeholder="Email" type="text" value="">
    <p>This is just me explaining how to use this particular field. It is very interesting, don't you know...</p>

JSfiddle link


  1. If the input with the placeholder="Email" is actually an email address, then the type attribute should be set to email, not text. (Reference:

  2. Declare an id attribute and a name attribute on the email field. This will be necessary if you want to access the elements or their posted values explicitly. (Reference: ,

  3. Once you have declared an id on the input, set the for attribute on the label equal to that id. This will enable a behavior such that clicking on the label will focus on the input for the corresponding field. (Reference:

  4. Use descriptive, semantic class names. Good class names should indicate the nature of the content, not the format of the layout. Instead of fieldwrapper try sender-email. (Reference : )

  5. This depends on what HTML version you are using, but the HTML5 spec says that form elements should be wrapped in p tags, not divs. (Reference:‘s-user-interface)

The code that would correspond to my comments might look like :

<p class="email-input">
    <label for="sender">Sender email address:</label>
    <input id="sender" name="sender" type="email" placeholder="Email" class="r2">
<p>This is just me explaining how to use this particular field. It is very interesting, don't you know...</p>

One thing you’ll notice is that there are less CSS classes. I have replaced the field-wrapper with email-input and completely removed the field class. You can migrate the .field-wrapper CSS to the .email-input selector, and the field CSS to the .email-input > input selector.

Leave a Reply

Your email address will not be published. Required fields are marked *