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">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.
<input id="search-box" name="q" size="25" type="text"/>
<input id="search-btn" value="Search" type="submit"/>
</form>
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">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:
<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>
<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">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-box" name="q" size="25" type="text" value="Enter search terms"/>
<input id="search-btn" value="Search" type="submit"/>
</form>
<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.




28 Comments:
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!!
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!
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?
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.
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
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 :)
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
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.
Thank you so much Amanda. Now, it looks great :)
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!
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
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=''"
Thanks Craig!!
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
so good. can you read this articles' turkish version with your site link ?
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?
I'm wondering how to change the order of the results--I want the newest post to come up first. Is that possible?
ur efforts r appreciated
This one helped! thanks
Thank you!!
Could you add rounded edges to a search box?
Can you add rounded edges to the search box?
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!
i hope this help. ;)
http://www.java-scripts.net/javascripts/Clear-Form-Field-Value-on-Click.phtml
Hi friend:
If we want to search "title only", but not include content.....what should we do??
Thanks.
Good one. Check my blog: serials4all.blogspot.com for new mp3 songs
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
This doesn't seem to work with the new search widget (powered by google). Is there any way to make that one cuter?
Post a Comment