Set Up Google Custom Search Engine: Step-by-Step
In this article
Yes, you can set up a Google Custom Search Engine (CSE) to search only your own site or a curated list of sites, and it takes about 10 minutes. You’ll get a search box you can embed on your website, and you can customize the look and which sites it searches. The free tier is enough for most personal or small business sites. Here’s exactly how to do it.
What You'll Need
- A Google account (free, any Gmail works).
- The URL(s) of the site(s) you want to search. For your own site, you need the domain, e.g.,
example.com. - Access to your website’s HTML if you want to embed the search box directly (or you can just use the public search page URL).
Step-by-Step
- Go to the Programmable Search Engine page. Open your browser and visit
programmablesearchengine.google.com. Sign in with your Google account if prompted. - Create a new search engine. Click the “Add” button (or “Create a new search engine” if it’s your first one).
- Define what to search. In the “Sites to search” field, enter the URL of the site you want to include. For your own site, type the domain without “www” (e.g.,
example.com). You can add multiple sites by pressing Enter after each one. - Set the language and name. Choose the primary language for your search results (e.g., English). Give your search engine a name—this is what appears on the search results page and in your dashboard. It can be your site name or something descriptive.
- Click “Create”. After you click Create, Google will generate a unique search engine ID (a long string of letters and numbers). You’ll see it on the next screen—copy it somewhere safe.
- Get your search code. On the “Overview” page, scroll down to the “Search engine ID” section. Copy that ID. Then click the “Get code” button to see the HTML snippet you can embed on your site. Copy the entire snippet.
- Embed the search box on your website. Paste the snippet into your website’s HTML where you want the search box to appear. If you use a CMS like WordPress, you can add it to a widget or a custom HTML block. The snippet includes a
<gcse:search>tag that loads the search box and results. - Test it. Open the page where you pasted the code. You should see a search box. Type a query and press Enter—results should appear on the same page (or on a separate results page if you configured that).
- Customize the look (optional). In the dashboard, go to “Look and feel” to change the layout (e.g., full-width or two-column), choose a color theme, or set the results to open in a new window. You can also upload a custom logo.
- Manage your search engine. Use the “Setup” tab to add or remove sites, change the search preferences (like whether to include similar pages), and set up search features like “Search by image” or “SafeSearch”.
Common Mistakes
- Entering the URL with “www” or “https://”. When adding a site to search, use the bare domain (e.g.,
example.com) unless you specifically want to search a subdomain. Including “https://” can cause the search to not match pages correctly. - Forgetting to add the search engine ID. If you copy the code snippet but don’t include the correct search engine ID (it’s embedded in the snippet automatically), the search box won’t work. Always copy the full snippet from the “Get code” section.
- Not waiting for indexing. If you’ve just created your site or added new pages, Google may not have indexed them yet. The CSE only searches pages that Google’s crawler has seen. This can take days or weeks.
- Using the wrong code for your platform. The default snippet uses the
<gcse:search>tag. If your website strips JavaScript or custom tags, you may need to use the alternative “JavaScript only” code (available in the “Get code” dialog). - Not setting a default search site. If you leave the “Sites to search” field empty, the CSE will search the entire web. That’s rarely what you want. Always add at least one site.
Tips
- Use the “Search the entire web but emphasize included sites” option. In the “Setup” tab, under “Sites to search”, you can check the box that says “Search the entire web but emphasize included sites”. This lets you search your site plus the rest of the web, with your site’s results ranked higher.
- Create multiple search engines for different purposes. You can have one for your blog, one for your documentation, and one for a curated set of external resources. Each has its own ID and can be embedded separately.
- Use the “Search engine ID” in API calls. If you want to use the Custom Search JSON API (for programmatic queries), you’ll need the same ID. Note that the API has separate quotas and billing—the free tier is limited to 100 queries per day.
- Customize the results page URL. In “Look and feel”, you can set the results to open in the same page or a different one. If you choose “separate page”, you’ll need to create a new page and paste a different snippet.
- Add a “Search” button to your site. The snippet includes the search box and a button. If you want a more integrated look, you can style the button with CSS.
Troubleshooting
Search box doesn’t appear on my site. First, check that you pasted the code correctly—it should include a <script> tag and a <gcse:search> tag. Make sure your website isn’t blocking JavaScript. If you’re using a CMS, try placing the code in a raw HTML block (not a text editor that strips tags).
Search returns “No results” for my own site. This usually means Google hasn’t indexed your pages yet. Go to Google.com and type site:yourdomain.com to see if any pages are indexed. If not, submit your sitemap in Google Search Console. Also, double-check that you entered the correct domain in the CSE settings.
Results are showing pages from other sites. If you selected “Search the entire web”, that’s expected. Go to “Setup” and uncheck that option, or make sure your included sites are listed correctly.
Search box works but results are ugly or not styled. The default look is basic. Use the “Look and feel” tab to choose a theme, or add custom CSS to override the default styles. The search results are rendered inside a container with the ID gsc-results—you can target that with CSS.
I lost my search engine ID. Log into the Programmable Search Engine dashboard. Your search engines are listed with their IDs on the “Overview” page. Click on the engine name to see the ID and get the code again.
The “Get code” button is missing. In the dashboard, click on the search engine name to open its settings. The “Get code” button is on the “Overview” tab, near the “Search engine ID” field. If you don’t see it, try refreshing the page.
Frequently Asked Questions
Is Google Custom Search Engine free?
Yes, the standard CSE is free for unlimited queries on your website. Google may show ads on the results page unless you turn off ads in the “Setup” tab (you need to enable “Ads” and then disable them). The JSON API has a free tier of 100 queries per day; beyond that, it costs money.
Can I search only a specific subdirectory like example.com/blog?
Yes. In the “Sites to search” field, enter the full path, e.g., example.com/blog. The CSE will include only pages under that path.
Can I use my own domain for the search results page?
No, the results are served on Google’s domain (or embedded in your page). You cannot use a custom domain for the search results URL without using the paid API and building your own interface.
How do I remove ads from my search results?
Go to “Setup” > “Search preferences” and look for the “Ads” section. Uncheck the box that says “Enable ads on search results”. This is available for free, but you must have an active search engine.
Can I search multiple websites at once?
Yes, just add multiple URLs in the “Sites to search” field, one per line. The CSE will search all of them together.
What’s the difference between CSE and the JSON API?
The CSE is a ready-made search box you embed on your site. The JSON API lets you send search queries programmatically and get results in JSON format. Both use the same search engine ID, but the API has separate quotas and billing.