35 Adding style to search forms
February 15, 2008 /

If you've added a search widget to your blog, you may be wondering how it could look a bit more stylish! After all, the default gray button isn't the most desirable button in the world.

Styling a search widget isn't difficult at all. You can customize the button using CSS or replace this with an image instead. Another customization option is to add some informative text inside the search box and remove the search button altogether.

In this post, we're going to look at some options and methods of customizing the search widget, so you can choose the method which works best for you and style your search box to match the overall design of your own customized blog.

In the previous installment of the Blogger Template Design Series, I explained an easy method of changing the layout of the header, enabling widget elements to be added. Search widgets are an excellent example of what could be included in a blog header, and in this post we will learn how search forms can be styled to suit your theme.

Search widgets are a type of form, constructed of a text box (the area where you type the search terms), a submit button, and some hidden elements which send information to the server about the search which is being performed.

If you're using a simple Blogger search widget, the code for your search widget will look something like this:

<form id="searchthis" action="/search" style="display:inline;" method="get">
<input id="search-box" name="q" size="25" type="text"/>
<input id="search-btn" value="Search" type="submit"/>
</form>
The elements which we can style are highlighted in red. The "search-box" element is the box which contains the search text, while the "search-btn" is the button keyed to submit the search query to the server.

By default, this simple search widget will appear like this in your template:

But using some simple techniques, we can make this look a whole lot prettier!

Using CSS to style the search widget

The easiest customizations can be achieved using only "inline CSS": this means that the search box and button can be styled within the code used for the search box.

For example, let's say we wanted the search box to have a pale blue background and a dark blue border. To achieve this, we simply add some style declarations to the "search-box" element, like this:

<form id="searchthis" action="/search" style="display:inline;" method="get">
<input id="search-box" name="q" size="25" type="text" style="background: #ccccff; border: 2px solid #000066"/>
<input id="search-btn" value="Search" type="submit"/>
</form>
By adding these style declarations, we can create a search form which looks like this:
We can add style to the search button in the same way. This time, the background will be dark blue with a red border, while the text is white and bold:
<form id="searchthis" action="/search" style="display:inline;" method="get">
<input id="search-box" name="q" size="25" type="text" style="background: #ccccff; border: 2px solid #000066"/>
<input id="search-btn" value="Search" type="submit" style="background: #000066; border: 2px outset #ff0000; color: #ffffff; font-weight: bold;"/>
</form>

Note that in this example, I used "outset" rather than "solid" for the border property; this ensures the button looks raised rather than flat, and helps readers understand that it is a button which can be clicked.

Here is the resulting form:

You can experiment with different colors ans styles for your own search form to create a unique design.

Changing the visible text within the form

You could add some text within the search box as a guide for your readers (eg: Search this blog!).

This is achieved by adding a "value" to the search box, like this:

<form id="searchthis" action="/search" style="display:inline;" method="get">
<input id="search-box" name="q" size="25" type="text" value="Enter search terms"/>
<input id="search-btn" value="Search" type="submit"/>
</form>
This will appear like this:
To change the text on the search button, we only need to change the value to our preferred term:
<input id="search-btn" value="Search" type="submit"/>
If you prefer the button to say "Go!", you could simply replace the value of "Search" with "Go!" instead:
<input id="search-btn" value="Go!" type="submit"/>

Using an image instead of a button

Using an image instead of a button isn't as complicated as you may think! For this, we simply need to change the input type from "Submit" to Image" and specify a URL for the image.

First of all, you will need to find the image you would like to use, and upload this to an external hosting account.

It is advisable to use a small image or icon for this (16x16px or slightly larger would be a perfect size for a search form). There are many free search icons available from Iconlet, or you could download an icon pack and choose a suitable image instead.

For this example, I'm going to use this icon from Iconlet:

To use this icon instead of the button for my search form, this is the code I will use:

<form id="searchthis" action="/search" style="display:inline;" method="get">
<input id="search-box" name="q" size="25" type="text" value="Enter search terms"/>
<input id="search-btn" value="Search" type="image" src="http://bloggerbuster.com/images/search-small.jpg" style="margin-left: 5px; margin: 3px 0 0 5px;"/>
</form>

Notice that I have changed the type of the input in this form from "submit" to "image", and have added the URL of my image afterwards. The style declarations align the image against the search box, adding some space to the left, and ensuring this doesn't float above the search box.

This is what the image will look like in the search form:

When using your own image instead of the submit button, be sure to reference the correct URL of your image.

You may also need to adjust the margins slightly for images of a different size to the one used in this example.

Coming soon...

In the next installment of the Blogger Template Design series, we will learn how to style links in a navigation bar using both CSS and icons.

If you have enjoyed this tutorial, please subscribe to the feed to receive updates of new posts.

Author: Amanda Kennedy

Amanda is a professional blogger and web designer living in Sheffield, United Kingdom.

In addition to curating Blogger Buster, you can find Amanda on Twitter, Facebook or add her to your circle on Google+.

Like to share?

You may also like to subscribe to Blogger Buster's RSS feed or receive free email updates of our latest posts.

35 Comments:

  1. This post is timely! I've been thinking of adding a search form in my blog, since I hid the blogger nav bar ontop.

    Even though the search function can still be accessible by hovering the top section, it's not user friendly.

    I'll try out your tutorial once I have some time in hand. Thanks Amanda!!

    ReplyDelete
  2. hi amanda,

    just finished reading your interview with the epiblogger.net .Why don't you post about it? heh.. :P

    heh..by the way, this is post is really great.I've bookmark it.

    well. if want to know, i'm your fan now..hahaha :)

    peace!

    ReplyDelete
  3. This is really nice, but is there any way to make the text in the search box dissapear when you click in this area, instead of having to highlight the text before typing?

    ReplyDelete
  4. For Black Zedd: Hope the search box implementation went okay for you? Feel free to let me know if you need help with this.

    For Apisz: I did (eventually) post about this on my weekly review. I wasn't sure how readers would respond to such an off-topic post, but now I know you're interested I'll make a point to mention it more prominantly in future! Thanks for mentioning it :)

    For Billy: That's a really good point! I'll look into this and will update this post when I know more about the method.

    ReplyDelete
  5. I'm self-hosting my Blogger powered blog but would like to use the search capabilities via a search form, as per your post. Do you know of any way this can be done, as the '/search' action won't work if you self-host.
    Thanks,
    Emma

    ReplyDelete
  6. For Emma,

    Thanks for bringing this to my attention. I haven't looked into the possibilities of blog search for self hosted blogs yet. One thing which I am sure would work for you would be Google's custom search though this would open search results in a different page to your blog. I'll do some research about a regular blog search and will let you know if I find anything which will be useful for you.

    Thanks for stopping by to comment :)

    ReplyDelete
  7. Hi amanda, love your blog and this post. I customized my search box but I wondered how to change the color of the text inside the box? Is that possible? Thanks

    ReplyDelete
  8. For Franzi: Yes it's certainly possible to change the color of the text. The text color can be changed by adding a line like this as inline CSS: color: #ff0000; (this would make the text bright red).

    For example, you could tag this on to the end of a border or font-weight statement.

    Hope this helps! Let me know if you need more help with this.

    ReplyDelete
  9. Thank you so much Amanda. Now, it looks great :)

    ReplyDelete
  10. Hi Amanda..Finally I got some spare time to put up the search function.

    To clear the default text, I've used the script from here.

    Thanks for the tips, work well for me!

    ReplyDelete
  11. Thanks very much.Your post helped me to add SearchThis on my blog resulting after Google banned my account.Always better to find a new option :)

    Thanks again.

    -Himanshu Sheth
    http://thoughtsprevail.blogspot.com

    ReplyDelete
  12. I love your blog and have found many helpful tips. I added this snippet to the search text box to remove the default text "Enter Search Terms" when the user clicks it. This might help someone else...

    onclick="this.value=''"

    ReplyDelete
  13. hi amanda

    i am wondering why any search queries for something like a number always fails to find anything. For example a part number. But searching by typing a description works

    ReplyDelete
  14. so good. can you read this articles' turkish version with your site link ?

    ReplyDelete
  15. Amanda, I love your site. I found many interesting tips that helped me design my blog. I have recently came across a big issue, I don't want to display the search results on my fist page but on a item page. Do you think is possible? I know that the results are displayed in this format: expr:action='data:blog.homepageUrl + "search"'

    How can I change this to something like data:blog.post.id???? Any suggestions?

    ReplyDelete
  16. I'm wondering how to change the order of the results--I want the newest post to come up first. Is that possible?

    ReplyDelete
  17. Could you add rounded edges to a search box?

    ReplyDelete
  18. Can you add rounded edges to the search box?

    ReplyDelete
  19. Oh my goodness, thank you SO much. You have really helped me understand all this html stuff, and make my search engine look exactly the way I want it to!

    ReplyDelete
  20. i hope this help. ;)
    http://www.java-scripts.net/javascripts/Clear-Form-Field-Value-on-Click.phtml

    ReplyDelete
  21. Hi friend:

    If we want to search "title only", but not include content.....what should we do??

    Thanks.

    ReplyDelete
  22. Good one. Check my blog: serials4all.blogspot.com for new mp3 songs

    ReplyDelete
  23. Hi Amanda
    Thanks for this I had been thinking of how I could add search and lo, you figured it out.
    Not realised you were in Sheffield though.
    Thanks.
    Paul Leeds in Yorkshire daily photo

    ReplyDelete
  24. This doesn't seem to work with the new search widget (powered by google). Is there any way to make that one cuter?

    ReplyDelete
  25. Hi Amanda! I so admire your knowledge in coding lol. If only i knew... wouldn't be typing this comment ;)

    Wondering if you can help; I cant get my search to search?? It keeps on giving me the "No posts matching the query" note. Ive tried so many diff kind of search forms, n it doesn't wanna search!

    Can you help??

    Heres my blog : http://www.beautyofchoosing.com/

    Hope u can!

    Thx a bunch!
    Mel

    ReplyDelete
  26. Hi Amanda!

    I so admire your knowledge in coding lol. If only I knew, wouldn't be typing this comment ;)

    Wondering if you can help; I cant get my search to search?? Ive tried various search forms and I keep on getting the "No posts matching the query" note??

    Heres my blog: http://www.beautyofchoosing.com/

    Hope u can help!

    Thx a bunch!
    Mel

    ReplyDelete
  27. I am thoroughly convinced in this said post. I am currently searching for ways in which I could enhance my knowledge in this said topic you have posted here. It does help me a lot knowing that you have shared this information here freely. I love the way the people here interact and shared their opinions too. I would love to track your future posts pertaining to the said topic we are able to read.

    ReplyDelete
  28. Thanks for taking the time to discuss this, I feel strongly about information and love learning more on this. If possible, as you gain expertise, It is extremely helpful for me. would you mind updating your blog with more information

    ReplyDelete
  29. I would like to see the same thing, Bobbi. It could be done by creating a post template, using css for the dotted-line border, and using this plugin for the actual clickable link. I think I’ll see if I can come up with something like that.

    ReplyDelete
  30. Thanks to share with us the information. I wish you good luck!

    ReplyDelete
  31. I just searching this kind of things in search engines. My searching was ending here. Keep up your good work. I bookmarked it for general updates.

    ReplyDelete

Great! You've decided to leave a comment! Please bear in mind that comments are often moderated and that rel="nofollow" is in use and spammy comments will be deleted. Let's have a meaningful conversation instead. Thanks for stopping by!

Browse through the Archives

All existing posts are still available to view while I'm working on the site, albeit seen in a much simpler interface. Feel free to browse through the archives to find tutorials, templates and articles to help you build a better blog:

Blog Archive

© Blogger Buster 2010 Home | About | Contact | Hire Me