Free tech support / small logo


How do you have rounded-edge HTML form text input boxes?

I was cruising around on the Web last night and came across a Web site that has cool rounded edges on its text input boxes within its search forms. Super cool. How do they do that? All of my HTML forms end up with the same boring square edges...


Dave's Answer:

And exactly what site were you visiting that you saw these sexy curves in the input box? :-)

Nevermind. Let's just make sure that we're talking about the same thing here, because I think you're just asking me a question about applying some CSS (cascading style sheets) styling to a standard HTML form with a text input box. Right?

So, for example, if you go to the Google home page, you see a big box where you can type in your search query. It's square, and it's rudimentary. Works for Google and its approach to minimal, uncluttered design, but, yeah, something a bit more rounded does add a bit of pizazz to things.

The basic of an HTML form can be summarized easily enough:

<form method="get" action="targeturl">
query:
<input type="text" name="q" />
</form>

This type of basic HTML form produces something like this:

query:

Yeah, boring is the word for it. Now we can wrap it in a box by adding a "div" tag, but let's actually figure out what the site you visited was doing to get the input box itself to have rounded edges.

Turns out what you're asking about is one of a number of super-cool additions to HTML forms that come courtesy of the new HTML 5 standard. In fact, simply replacing "text" with "search" magically transforms that input box to be exactly what you want:

query:

Tip: if you don't see it, it's because your Web browser isn't HTML5 compatible. Get a newer one, it should be different! :-)

Easy enough, isn't it?

Now it turns out that upon reading the HTML 5 input element spec that there's a bunch of neat stuff you can do, like automatically have page focus jump to that input box (as Amazon does with its search box) by adding autofocus, and you can even now have text that appears in the box, just to vanish as soon as someone starts typing, by using the attribute placeholder="text".

Let's see "placeholder" in action. Source code first:

<form method="get" action="targeturl">
<input type="search" placeholder="Enter query" />
</form>

And the resultant input box, all tricked out:

What do ya think?

HTML5 now also includes a bunch of other specific data types, though how the browser handles those specific types is still up for grabs. If nothing else, I'm sure it helps with filling out forms automatically. The most useful? type="email", type="url", and type="number".

Actually, HTML5 has some very cool tricks for entering numbers, including the ability to have a slider (that's type="range" if you want to Google it), but type="number" is my favorite. Here's a simple example:

<form method="get" action="targeturl">
Pick a number between 0-100: <input type="number" min="0" max="100" value="50" />
</form>

and the result:

Pick a number between 0-100:

Tell me that's not darn cool!

Armed with those you should be able to quickly and easily spiff up your HTML forms on your site. Now, it won't work with every single Web browser out there, but by definition, it'll all default to reasonable behaviors anyway, so there's really no reason not to do it. Now excuse me while I check the forms on my site to see if they're updated for HTML5...


Also check out:








Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments (4) · Add Comment

It looks no different in Firefox 3.6, Chrome or Internet Explorer 9?

Posted by: Ray at March 4, 2011 12:54 PM

"something a bit more rounded does add a bit of pizazz to things."

I'm sorry but I see no "rounded" edges when viewing the examples in Firefox 4 (beta 12), Chrome 9 and Internet Explorer 8. Sure, the "search" examples in these newer browser do show a text input box with an [x] and with a placeholder comment, but I think the author might have misunderstood what "type='search'" is intended to do visually to an input field ... or perhaps is using a browser (Mac Safari?) that does make the fields curved and assumes this is an HTML 5 standard feature on all browsers?

Article's claims need checking, though.

Posted by: John Smith at March 4, 2011 2:21 PM

"Tip: if you don't see it, it's because your Web browser isn't HTML5 compatible. Get a newer one, it should be different!"
I don't see the rounded edges either. I've tried IE 8 and Firefox 3.6.15. I'm new to this stuff so, how do I know what version I have? How do upgrade to html5 and do I need to?
Thanks,
Tammy

Posted by: Tammy at March 15, 2011 12:33 AM

John and Tammy, HTML5 is so new, and there are so many elements to it that it's possible that it's only the beta releases (not the main public releases) of the latest browsers that are starting to include HTML5 elements. Soooo.... it might be a while before this shows up in your browser and when it does, odds are good that it will be without any fanfare. You'll just notice one day - as I did - that the search box is shaped differently.

Posted by: Dave Taylor at March 15, 2011 6:47 AM
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.