Skip to content

GCSE: Site Search with Locally Hosted Search Results

These instructions are for using a Google Custom Search Engine (GCSE) campus search. This option searches for content in your site, or in a specific collection of sites that you identify (as opposed to searching all sites), and displays search results on a locally hosted page within your website.

Site search on a locally hosted results page

Example Results A (default)

Example Results B (custom)

1. Create a local page in your site to host the search results

We recommend creating either a page or a directory+index page in your website's root directory named "search". On this page, you will need a large search box that spans across the page. You can either use the default GCSE search box (easiest option - nothing to do on your part), or you can create your own to make it look fancier (see examples above).

2. Insert the GCSE campus search code on the page

You will need to contact the GCSE administrators in order to obtain the code for your site.  The GCSE site administrators have a registered non-profit account with Google which will allow you to exclude ads from displaying in your search results.   If you choose to create your own GCSE account, your search results will contain ads.

To request code for your site, please send an email to  Include the following information:

  • Your contact info
  • List of URLs you want searched
  • Whether you would like to use the default GCSE search box on your search results page, or whether you would like to use a custom one

3. Add the search box HTML code

Add the following HTML code to your pages or template where you would like to see the search box that will search the entire campus.

<form id="gcse_search" action="/<search-page-path>" method="get" name="search" role="search">
<label for="gcse_searchbox">Search Site:</label>
<input id="gcse_searchbox" type="text" name="q" value=""
title="enter search terms" onfocus="noWatermark();"
onblur="watermark();" />
<input id="gcse_searchbutton" type="image" name="btnG" value="Submit Search"
title="submit search" alt="submit search" />
<img src="//" onload="loadWatermark();">

4. Add the styles and scripts

Each individual web site uses different styles and scripts that may affect this search code differently.  The following is a best attempt of trying to make the search box look and function correctly in most sites.

Add the following style and script code into your HTML pages or template so that it shows up in the <head> section of the pages with your search box.

<style type="text/css">

    border:1px solid black;
    margin: 0;
    width: 230px; 

  #gcse_searchbox {
    color: #666;
    font:15px Helvetica, san-serif;
    padding:3px 5px;

  .gcse_watermark {
    background: #FFF
                no-repeat 5px 3px; 

  #gcse_searchbutton { 

  #gcse_searchbutton:active {

  #gcse_search label {

<script type="text/javascript">

  // add or remove watermark if no text is entered
  function watermark(){
    if (inputId.value.length > 0){
      if (inputId.className == "gcse_watermark")
        inputId.className = "";
      inputId.className = "gcse_watermark";

  // remove watermark when input has focus
  function noWatermark() {
    inputId.className = "";

  var inputId; //declare reference to input 
  function loadWatermark() {
    inputId = document.getElementById("gcse_searchbox"); 
    watermark(); //initialize watermark


You may also download and use GCSE images locally


Last Updated: 11/10/23