Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


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...


More Useful HTML, JavaScript and Web Site Programming Articles:
✔   How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔   Can I embed a Facebook search box on my blog site?
I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔   Can I use CSS for drop shadows on my blog?
I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔   How can I embed interactive photo panoramas on my site/blog?
I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔   How can I create a Twitter search URL shortcut?
I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  





Categorized: HTML, JavaScript and Web Site Programming , HTML, JavaScript and Web Site Programming   (Article 9819, Written by )
Tagged: css, form design, html, html5, user input, web design
Previous: How do I add photos to my iPod from my Windows PC?
Next: Add names and contacts to my iPod from Windows PC?




Reader Comments To Date: 4

Ray said, on March 4, 2011 12:54 PM:

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

John Smith said, on March 4, 2011 2:21 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.

Tammy said, on March 15, 2011 12:33 AM:

"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

Dave Taylor said, on March 15, 2011 6:47 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.

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, Dave, for all your helpful information by buying you a cup of coffee!

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











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 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. Further, 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. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.