Ask Dave Taylor
  • Facebook
  • Instagram
  • Linkedin
  • Pinterest
  • Twitter
  • YouTube
  • Home
  • YouTube Videos
  • Top Categories
  • Subscribe via Email
  • Ask A Question
  • Meet Dave
  • Home
  • HTML & Web Page Design
  • How can I add a Google search box to my Web site?

How can I add a Google search box to my Web site?

December 9, 2004 / Dave Taylor / HTML & Web Page Design / 879 Comments

Dave, I keep visiting sites and seeing these cool search boxes that let you either search their entire site or search the entire Google database, all without leaving that page! I want to have something like this and would appreciate your helping me figure out the code needed.

This is a question that’s going to result in some HTML listings. You know that, so there’s no reason to panic!

First off, the good news. Google itself actually has a nice page offering you HTML code you can just cut and paste onto your own Web pages to produce the search box you seek, and some variants beside. Just check out Google Free.

Instead of relying on the bright sparks at Google, though, let’s go through the steps of building our own search box instead, so you’ll be able to see how it works.

Also, not to pick on Google because I think the world of those folk, but their HTML samples could be cleaned up a bit, usually, so I’ve also recast it as proper XHTML rather than somewhat sloppy HTML. Just don’t tell Larry and Sergey, okay?

The basic technique involved here is to be able to manipulate one of the variables handed to the Google search engine, a variable called sitesearch. Set it to a null value and you’re searching the entire World Wide Web, but set it to a specific domain and it’s constrained exactly as if you had typed in the Google special notation site:domain.

In addition to that, you need an input field and a submit button. Put them all together and here’s the minimalist Google search form that lets the user alternate between just your site (well, in this case just my site) or the entire Web:

<form method="get" action="http://www.google.com/search">
<input type="text"   name="q" size="31"
maxlength="255" value="" />
<input type="submit" value="Google Search" />
<input type="radio"  name="sitesearch" value="" />
The Web
<input type="radio"  name="sitesearch"
value="askdavetaylor.com" checked /> Ask Dave Taylor<br />
</form>

There are some additional tweaks we can apply to make it a bit more fancy, including changing the radio buttons to a single check box, and aligning things a bit more nicely using a table and some simple CSS:

<form method="get" action="http://www.google.com/search">
<div style="border:1px solid black;padding:4px;width:20em;">
<table border="0" cellpadding="0">
<tr><td>
<input type="text"   name="q" size="25"
maxlength="255" value="" />
<input type="submit" value="Google Search" /></td></tr>
<tr><td align="center" style="font-size:75%">
<input type="checkbox"  name="sitesearch"
value="askdavetaylor.com" checked /> only search Ask Dave Taylor<br />
</td></tr></table>
</div>
</form>

Here’s how that renders when included on an HTML page:


only search Ask Dave Taylor

If you’d like to use this on your own site, simply change the occurrences of askdavetaylor.com as appropriate.

Not too hard at all!

About the Author: Dave Taylor has been involved with the online world since the early days of the Internet. Author of over 20 technical books, he runs the popular AskDaveTaylor.com tech help site. You can also find his gadget reviews on YouTube and chat with him on Twitter as @DaveTaylor.

Let’s Stay In Touch!

Never miss a single article, review or tutorial here on AskDaveTaylor, sign up for my fun weekly newsletter!
Name: 
Your email address:*
Please enter all required fields
Correct invalid entries
No spam, ever. Promise. Powered by FeedBlitz
Please choose a color:
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!

879 comments on “How can I add a Google search box to my Web site?”

  1. Dennis Weidner says:
    November 10, 2020 at 2:56 pm

    When I loaded your HTML code. It just did regular Google searhes, not site seraches

    Reply
    • Dave Taylor says:
      November 11, 2020 at 9:16 am

      Did you change the [[ input type=”checkbox” name=”sitesearch” value=”askdavetaylor.com” checked /]] line to specify your own domain name, Dennis?

      Reply
  2. Zapada says:
    April 8, 2018 at 10:04 pm

    Hi Dave,

    When I tried adding it to my website, it kept reloading the page instead of searching anything.

    Do you know what might be happening?

    Thanks,

    Reply
    • Dave Taylor says:
      April 9, 2018 at 8:10 am

      Are you doing a “view source” and confirming that the copy/paste action hasn’t broken anything? Pay close attention to quotes; sometimes they go from “straight quotes” to curved ones, which will definitely break the HTML code.

      Reply
  3. Beth Kishiro says:
    February 11, 2018 at 6:39 pm

    Thanks for the great article and html. It looks great but does not search most words, wonder what could be the issue? I am using a template with list and it will search a few words but for most words it results in 0.

    Reply
  4. Ajay Bhalerao says:
    September 19, 2017 at 11:11 pm

    hi Dave

    you have provided very good information of custom search box for ,keep it up and good going

    ajay bhalerao

    Reply
  5. Euan says:
    May 31, 2017 at 7:07 am

    Hi, can you do the same thing with other sites like wikipedia or bing ?

    Reply
    • Dave Taylor says:
      May 31, 2017 at 10:36 am

      How about this article: https://www.askdavetaylor.com/add_wikipedia_search_box_to_my_web_site_or_blog/

      Reply
  6. ang says:
    March 27, 2017 at 9:00 pm

    hi, when i insert your code into my script, it did work but not on all pages of my site. is it possible to have the search box on all my pages? thanks

    Reply
    • Dave Taylor says:
      March 28, 2017 at 12:56 pm

      Not sure why it would work on some pages but not others. What’s different about the pages where it doesn’t work? PHP? Entries vs Pages on WordPress?

      Reply

Comment navigation

← Older Comments

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Recent Posts

  • Chromebook Owner’s Guide to Antivirus & Anti-Malware Solutions
  • Everything You Need to Know about Apple’s Clean Energy Charging
  • How Can I Watch Free Classic Movies on my Windows PC?
  • How Can I Maximize Online Privacy with a VPN Connection?
  • SCAM: Did I Just Buy A Computer From Amazon? I Demand a Refund!

On Our YouTube Channel

TWT Audio REVO TW310 Budget Headset -- DEMO & REVIEW

iClever Bluetooth 34-Key Number Pad Keyboard -- REVIEW

Categories

  • AdSense, AdWords, and PPC Help (106)
  • Amazon, eBay, and Online Shopping Help (164)
  • Android Help (228)
  • Apple iPad Help (147)
  • Apple Watch Help (53)
  • Articles, Tutorials, and Reviews (346)
  • Auto Tech Help (17)
  • Business Advice (200)
  • ChromeOS Help (34)
  • Computer & Internet Basics (782)
  • d) None of the Above (166)
  • Facebook Help (384)
  • Google, Chrome & Gmail Help (188)
  • HTML & Web Page Design (247)
  • Instagram Help (49)
  • iPhone & iOS Help (625)
  • iPod & MP3 Player Help (173)
  • Kindle & Nook Help (99)
  • LinkedIn Help (88)
  • Linux Help (174)
  • Linux Shell Script Programming (90)
  • Mac & MacOS Help (914)
  • Most Popular (16)
  • Outlook & Office 365 Help (33)
  • PayPal Help (68)
  • Pinterest Help (54)
  • Reddit Help (19)
  • SEO & Marketing (82)
  • Spam, Scams & Security (96)
  • Trade Show News & Updates (23)
  • Twitter Help (222)
  • Video Game Tips (66)
  • Web Site Traffic Tips (62)
  • Windows PC Help (951)
  • Wordpress Help (206)
  • Writing and Publishing (72)
  • YouTube Help (47)
  • YouTube Video Reviews (159)
  • Zoom, Skype & Video Chat Help (62)

Archives

Social Connections:

Ask Dave Taylor


Follow Me on Pinterest
Follow me on Twitter
Follow me on LinkedIn
Follow me on Instagram


AskDaveTaylor on Facebook



microsoft insider mvp


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 site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to our terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. Our lawyer says "Thanks for your cooperation."
© 2023 by Dave Taylor. "Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.
Privacy Policy - Terms and Conditions - Accessibility Policy