HTML5 Forms

In addition to new tag elements in HTML5 the input element has been extended with new types and attributes. Although these changes are not fully supported across all browsers they can still be added if desired to your existing websites.

New input attributes

Placeholder Text

It is common practice to include placeholder or default text in form input fields. In most cases they simply describe what data should be entered and once a user clicks or focuses on the field the value is displayed. HTML5 specifications has added the placeholder attribute to input elements so that browsers will perform this function instead of having it performed by JavaScript. However until it is supported by all browsers you will still need to use JavaScript.

<form>
    <input name="query" placeholder="Search" />
</form>

Auto Focus

You may in your websites be using a piece of JavaScript to focus a form field after a page has loaded. To make this task easier the autofocus attribute has been added.

<form>
    <input name="name" autofocus />
</form>

New input types

The greatest thing about the input element is that if it doesn’t recognize the type (e.g. the browser doesn’t support the type) then it will default back to a text input field. That means that if you want to use any of the new input types like search and email then you can do so without worrying about missing form fields.

Search Input

In HTML5 it was decided to add a search type input. As you all know in your web pages you typically use a normal text type input for your search forms. However it was decided that the new search type should be added so browsers could add additional functionality to them to match the browsers search functionality. What this means is that each browser can do what they want with the field including changing the style to match the browser’s search so that it no longer is consistent with the rest of your web page.

<form>
    <input name="query" type="search" />
</form>

URL & EMAIL Input

Both URLs and emails are strings that conform to respective Internet Standards. To make validation consistent and easier for developers the url and email type input elements have been added. The purpose of these fields is to verify and restrict the inputted data so only valid information is sent back to the server. However this validation would be performed at the browser level and if you are verifying other fields you will end up having to manage multiple error messages to the user which could be confusing to them.

<form>
    <input name="email" type="email" />
    <input name="website" type="url" />
</form>

Sliders and Spinboxes

Ever wanted to have simple easy to use slidebars or spinboxes when a user is inputting number values. In HTML5 your wish has been granted with the number and range input types. These elements allow you to set a minimum and maximum value as well as a step value for how it should be incremented. Again allowing the browser to display their version of sliders and spinbox controls and you not having to implement a JavaScript library to get your desired elements.

<form>
    <input type="number" min="8" max="29" step="1" value="12" />
    <input type="range" min="0" max="10" step="2" value="6" />
</form>

Calendar and Color Pickers

Commonly you will find yourself requesting that a user input a date or time and to handle this you will most likely include a JavaScript calendar to get your desired date picker. Similarly to number inputs, HTML5 adds support for input of various date types including month, date and time. These elements if supported by the browser would present a calendar interface for selecting a valid value. Less common but also specified is the color picker element defined by type color, however at this time no current browser supports the element.

<form>
    <input type="color" />
    <input type="date" />
    <input type="time" />
</form>

HTML5 raises some developer complications and in my opinion is incomplete. The specifications outline the details on common elements currently created by JavaScript, however they do not specify how those objects are to be rendered. What this means is that it is up to the browser on how they are displayed and are no longer in the control of the designer/developer. In addition it introduces the concept of browser validation of input yet once again it doesn’t specify how the browser should handle the validation or how the designer/developer can tap into the validation. With complicated forms it is often the case that input is validated not only for standards but for required fields or custom data values, by including the new HTML5 elements you know have to worry about validation errors from your own scripts but also the browser and the multiple feedback could be confusing to your Users.

I understand that HTML5 is taking the first steps in expanding the common functionality of the web and it’s browser, however to make these new elements a viable choice for web developers/designers more specifications need to be detailed in how a browser is to behave. For example if you have a web form that is styled to match your site and the browser displays search input that doesn’t match your site then it won’t be used, same with calendars and color pickers. A good start definitely but don’t expect to see these elements commonly used for a while to come.

Resources

, , , , , , , , , , , , ,

Ah don’t you just enjoy all the hype and sniping that goes on when new features or standards are released. HTML5 has started things off with a bang, regardless of the actual full standard still being years away from being finalized, Web Browsers have jumped on implementing the new tags and functions. I don’t want to focus on the Audio/Video functionality of HTML5 instead for the moment lets simply have a look at some of the new tags that are part of the standard.

The Nav Tag

In HTML5 they have defined the new tag nav according to the documentation it functions the same as a div tag. The only difference is that it is used to contain navigation links and elements. The purpose behind the tag is to distinguish ad links, and other a tags in a website from the actual navigation. This tag is usefull for screen readers and similar products that assist the disabled, however the issue really comes down to why is it needed. Seriously all websites define navigation differently and I for one do not see existing developers or new ones being like oh its a navigation to go to the next page i must put it in a nav tag.

<nav>
    <a href="home.html">Home</a> | 
    <a href="about.html">About</a> |
    <a href="contact.html">Contact</a>
</nav>

The Footer and Header Tag

Similar to the nav tag new footer and header tags have been defined. Why?? not all websites or pages will have footers and headers, and when they do for what purpose would you need to define a separate tag to define them. Once again the div tag serves the same purpose.

<body>
<header>
    <p>header Content</p>
</header>
<div>
    <p>Some Content</p>
</div>
<footer>
    <p>Footer Content</p>
</footer>

The Meter and Time Tags

Some additional impractical tags are the meter and time tags. These tags are supposed to be used to designate a measure and time respectively. However they behave as a span tag. I guess using the time tag the browser if it wanted could convert the displayed time into the users local time, that is if they specify the TimeZone and other information. As for having a meter tag to define a measure whether it is a percentage or a rating that is just plain impractical. If I was writing an article I wouldn’t take the time to go back though and wrap all my analytical data with meter tags.

<meter>75%</meter>
<meter>4 out of 5</meter>
<time>12:00 PM</time>
<time datetime="2002-05-17">Chad's Birthday</time>

The Menu Tag

The purpose of this tag for some reason I can’t fathom. It says in the specifications it is used to contain menu controls such as check boxes and etc, but for what purpose I have no clue. I can not think of a reason to use the menu tag in a website especially as the samples put list items in it, why wouldn’t you just use the ul or ol tags.

<menu>
<li><input type="checkbox" />Apple</li>
<li><input type="checkbox" />Banana</li>
</menu>

The Article Tag

The article tag is actually a good idea, imagine that. It’s purpose is to contain information that is not part of your site but instead of came from somewhere else. Have a scientific article that you are referencing a graph or data set from another source than wrap it in an article tag and it is known the content isn’t yours, combine it with the address tag and you have effectively cited the content.

<article>
    <p>Content</p>
</article>

Summary Wrap Up

So HTML5 has defined new tags to segregate the content on a website, including everything from headers, to articles, to sections, and even time. To put it simply … why? Everyone creates and designs their websites differently using different formats and breakdowns of contents, yes it would make it easier for the browser and the impaired but is it feasible that a normal content manager writing content would wrap their text in the tags, not at all. All the new tags are is simply more bloat to HTML serving no new functionality or benefit to the web. Of course I purposely didn’t mention the audio and video tags but I’ll discuss those later in their own article.

, , , , , , ,