One of the elements most frequently used by websites is probably the search box. If you want to improve user experience in a simple way, and make it easy to search and find content for your users, then you have to add a search form on your website.
So, today we’re going to cover how to style a search form using the most exciting CSS3 features.

You’ve already seen before how to create a cool CSS3 search box and now you’ll see how can you create the above CSS3 search form with 3D look using CSS3 box-shadow.
The markup
Below you’ll find the HTML used for this search form. Note the HTML5-specific placeholder and required attributes.
While I initially wished to use the HTML5′s type="search" for the search input, I gave up because of cross browser inconsistency. For now, apparently you need to add some extra CSS lines to override the defaults.
<form class="form-wrapper"> <input type="text" id="search" placeholder="Search for CSS3, HTML5, jQuery ..." required> <input type="submit" value="go" id="submit"> </form>
The CSS
Here are the minimal styles used to create this beautiful CSS3 search form:
.form-wrapper {
width: 450px;
padding: 8px;
margin: 100px auto;
overflow: hidden;
border-width: 1px;
border-style: solid;
border-color: #dedede #bababa #aaa #bababa;
-moz-box-shadow: 0 3px 3px rgba(255,255,255,.1), 0 3px 0 #bbb, 0 4px 0 #aaa, 0 5px 5px #444;
-webkit-box-shadow: 0 3px 3px rgba(255,255,255,.1), 0 3px 0 #bbb, 0 4px 0 #aaa, 0 5px 5px #444;
box-shadow: 0 3px 3px rgba(255,255,255,.1), 0 3px 0 #bbb, 0 4px 0 #aaa, 0 5px 5px #444;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
background-color: #f6f6f6;
background-image: -webkit-gradient(linear, left top, left bottom, from(#f6f6f6), to(#eae8e8));
background-image: -webkit-linear-gradient(top, #f6f6f6, #eae8e8);
background-image: -moz-linear-gradient(top, #f6f6f6, #eae8e8);
background-image: -ms-linear-gradient(top, #f6f6f6, #eae8e8);
background-image: -o-linear-gradient(top, #f6f6f6, #eae8e8);
background-image: linear-gradient(top, #f6f6f6, #eae8e8);
}
.form-wrapper #search {
width: 330px;
height: 20px;
padding: 10px 5px;
float: left;
font: bold 16px 'lucida sans', 'trebuchet MS', 'Tahoma';
border: 1px solid #ccc;
-moz-box-shadow: 0 1px 1px #ddd inset, 0 1px 0 #fff;
-webkit-box-shadow: 0 1px 1px #ddd inset, 0 1px 0 #fff;
box-shadow: 0 1px 1px #ddd inset, 0 1px 0 #fff;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
.form-wrapper #search:focus {
outline: 0;
border-color: #aaa;
-moz-box-shadow: 0 1px 1px #bbb inset;
-webkit-box-shadow: 0 1px 1px #bbb inset;
box-shadow: 0 1px 1px #bbb inset;
}
.form-wrapper #search::-webkit-input-placeholder {
color: #999;
font-weight: normal;
}
.form-wrapper #search:-moz-placeholder {
color: #999;
font-weight: normal;
}
.form-wrapper #search:-ms-input-placeholder {
color: #999;
font-weight: normal;
}
.form-wrapper #submit {
float: right;
border: 1px solid #00748f;
height: 42px;
width: 100px;
padding: 0;
cursor: pointer;
font: bold 15px Arial, Helvetica;
color: #fafafa;
text-transform: uppercase;
background-color: #0483a0;
background-image: -webkit-gradient(linear, left top, left bottom, from(#31b2c3), to(#0483a0));
background-image: -webkit-linear-gradient(top, #31b2c3, #0483a0);
background-image: -moz-linear-gradient(top, #31b2c3, #0483a0);
background-image: -ms-linear-gradient(top, #31b2c3, #0483a0);
background-image: -o-linear-gradient(top, #31b2c3, #0483a0);
background-image: linear-gradient(top, #31b2c3, #0483a0);
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
text-shadow: 0 1px 0 rgba(0, 0 ,0, .3);
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #fff;
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #fff;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 1px 0 #fff;
}
.form-wrapper #submit:hover,
.form-wrapper #submit:focus {
background-color: #31b2c3;
background-image: -webkit-gradient(linear, left top, left bottom, from(#0483a0), to(#31b2c3));
background-image: -webkit-linear-gradient(top, #0483a0, #31b2c3);
background-image: -moz-linear-gradient(top, #0483a0, #31b2c3);
background-image: -ms-linear-gradient(top, #0483a0, #31b2c3);
background-image: -o-linear-gradient(top, #0483a0, #31b2c3);
background-image: linear-gradient(top, #0483a0, #31b2c3);
}
.form-wrapper #submit:active {
outline: 0;
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
}
.form-wrapper #submit::-moz-focus-inner {
border: 0;
}
Browser support
Below you can find some screenshots with the search form. You’ll notice that it degrades really nice across older browsers. I would add that this CSS3 search form is a ready-to-use one.
Modern browsers like Chrome, Firefox, Safari, Opera, IE10:

Please note that, at this time, Opera supports the HTML5 placeholder attribute but is not styleable for now.
A good news is that Internet Explorer 10 will also support the HTML5 placeholder.
IE trident (IE6/IE7/IE8):

Conclusion
If you read my previous articles, then you already know that here we’re doing stuff that works (with or without fallbacks) across all browsers. Also, this example is not an exception.
Besides using this CSS3 form to create a searchbox, you could easily adapt this for a signup form or for a email subscription form.
Feel free to use this CSS3 search form in your projects and please let me know your thoughts!
As always Red, amazing work!
+1
Yeah, I wasn’t expecting anything less as usual. Really cool stuff.
Thank you guys, it’s always nice to hear that! ;)
Wow!! i really like the way you make all these stuff!! awesome 4xboxShadow effect!!
Alejandro, thanks for your comment! I’m glad you like the stuff I do.
This is one awesome search form. Thanks for the great share!
Thank you Jon! ;)
really helping tips you sharing in this tutorial. thanks
Hi again Red,
Few days back I came across your site for the first time and found that your way of coding is really good. Though I’ve already implemented this kind of functionality, look and feel in the search box few days back, but even after going through your code, I’d like to say:- I’m fascinated about your coding pattern, it’s clean and structured.
I really appreciate it.
Thanks Jimmy, I also appreciate your comment!
great, how do you see the results of the search?
Bob, you need to implement something like Google Custom Search in order to view results.
Hi Red,
Excellent samples and very useful stuff. Great work!
Thanks, it’s always nice to hear you like my work.
Hi, i have tried the above code on my html page but i don’t know how the search works, i mean for example i have pdf books on my website then how to add a search box that every visitor can find a pdf book. I have asked my hosting provider (http://www.varyhost.com) but they said ask your web designer.
Please help!
Jonny, first of all you need to implement something like Google search on your website.
And then, when you’ll have this custom search working, you can customize its look using this tutorial.
Hope that helps!
Hello, Red!
Thank you for all these awesome techniques you post here.
Could you please explain me one point: why does the height property of the ‘submit’ button must be 2px more than the height property of the input field in order for them both to have the same height on the screen? I just code a website here, and it only proved once again that the button’s height property must be 2px more. Just wonder why?
Thanks in advance.
Dimitry, to overcome this kind of of issues, you could set for both inputs (text and submit) the same box sizing model (using
box-sizing) as:This happens because apparently the
input type="submit"inheritsbox-sizing: border-box.Hope that helps.
Catalin
Good Work
Excellent work.
Hi Red,
thanks for this tutorial, good work.
I have used these techniques for creating another CSS3 search form. Instead of the “placeholder” attribute I created a simple jQuery validation with a popup appearing when the user leaves the search field empty.
It’s available here: http://www.azmind.com/2012/04/15/clean-search-form-css3-jquery-psd/
very good
nice