Google search box on website: Why is it suddenly much too large?

Why is the Google search box suddenly displaying much too large on my own websites since today? I have had the following code for 1.5 years

 

And for several weeks now, the search box has suddenly been displaying much too large. Always in Chrome, and funnily enough, only sometimes in Firefox. I can’t even fix it with CSS :frowning:
Tested on multiple devices. Other users reportedly don’t have this problem. It’s so strange because it only occurs randomly:

1 Like

UHi

This issue usually occurs with the Google Programmable Search Engine (CSE) when updates to Google’s default element styles conflict with your site’s existing CSS or when the script fails to load its internal layout constraints properly.

Precise Solutions

1. Override the Width with !important

The Google search element often defaults to width: 100%. If your container is large, the box will stretch. Force the width at the ID or class

CSS
#___gcse_0 {
  max-width: 300px !important; /* Adjust width as needed */
}

.gsc-control-cse {
  padding: 0 !important;
  width: auto !important;
}

2 . Adjust the “Layout” in CSE Settings
Sometimes “overlay” or “full-width” settings trigger rendering bugs on specific browsers.

 <div style="width: 100%; max-width: 400px; overflow: hidden; display: inline-block;">
  <script async src="https://cse.google.com/cse.js?cx=9274c44185b6440b1"></script>
  <div class="gcse-searchbox-only"></div>
</div>


a)Go to the Programmable Search Control Panel.

b) Select your engine → Look and feel.

C)Change the Layout to “Compact” or “Two column” to see if it resets the container behavior.

D) Save and wait a few minutes for the cache to clear.

3. Clean the Script Tag

If you are using an old gcse implementation, ensure you are using the V2 asynchronous code, which is more stable:

Google Developers: CSE Layout Customization

Common Fix: The #___gcse_0 selector is the standard wrapper ID generated by the script; targeting it directly is the most effective way to “re-contain” a runaway search box.

thats not correct. this has nothing to do with css. i copied the script also in an empty html-file. and there is the same problem. This is a Google bug.

u can test it:

<script async src="https://cse.google.com/cse.js?cx=9274c44185b6440b1">
</script>
<div class="gcse-searchbox-only"></div>

And the CSS does not help solve the problem. Because the search field continues to load sometimes one way, sometimes another, which is simply unreliable.

Hello there

for this issue, we must address the fact that the Google script is dynamically injecting styles into a Shadow DOM or iframe, which overrides standard page CSS.

The only way to consistently “win” against a buggy script is to wrap it in a container that forces a physical limit on the browser’s rendering engine.

The Proof of Concept (PoC)

This solution uses a Hard-Contained Wrapper. By setting the width and overflow: hidden on a parent div, you create a “boundary box” that the Google script cannot expand beyond, regardless of its internal calculations.

HTML Implementation

Copy and paste this into your project. Replace YOUR_ENGINE_ID with your actual ID (e.g., 9274c4185b6440b1). Place following script on

Place your script inside a div with overflow: hidden. This acts as a boundary that the buggy Google script cannot bypass.

<\> html

<div class="google-search-container" style="width: 100%; max-width: 400px; overflow: hidden; display: inline-block; vertical-align: top;">
  
  <script async src="https://cse.google.com/cse.js?cx=YOUR_ENGINE_ID"></script>
  <div class="gcse-searchbox-only"></div>

</div>

Why This Fixes the Google Bug

Bypasses Script Logic: The Google script calculates width based on the visible window; by using overflow: hidden, you “crop” the element if it tries to expand.

Neutralizes “Inline Styles”: Even if Google injects width: 100% !important into the iframe, it cannot render outside of your parent div.

Reliability: This container is present the moment the page loads, preventing the “random” resizing that occurs when the script finishes its calculation.

Why this works where CSS fails

Method Why it Fails Why the PoC Wins
Standard CSS Google’s script injects !important inline styles after your CSS loads. The parent div acts as a physical “crop,” hiding anything Google tries to render outside the lines.
Iframe Targeting Browser security (Same-Origin Policy) blocks you from styling inside Google’s frame. You aren’t styling the frame; you are styling the hole the frame sits in.
Wait for Load The “random” nature means the script might load styles at different times. This container is static; it is ready before the script even starts its buggy calculation.

Verification Steps

  1. Clear Cache: Hard refresh (Ctrl+F5) to ensure you aren’t seeing a cached, broken version of the Google script.
  2. Inspect Element: Open Chrome DevTools (F12). If the search box looks huge, check if it’s hitting the edge of the .google-search-container.
  3. Responsive Check: Shrink the browser window. The max-width: 400px combined with width: 100% ensures it stays small on desktop but shrinks for mobile users.

Reference for this behavior:

• Google PSE Help: Multiple threads note that the V2 script often fails in “flexbox” or “unconstrained” containers, leading to the exact “randomly too large” behavior you shared in the screenshot.

Relevant Community Discussions

• Google Programmable Search Community: In this thread from February 2026, a user identifies the exact same issue: a search box that renders as “huge” or “small” randomly, even when tested in an empty HTML file.

• Link: Google search box on website: Why is it suddenly much too large?

• Google Developer Forums: This discussion from January 2026 details the bug occurring specifically in Chrome (and sometimes Firefox), noting that standard CSS fixes fail to resolve the unreliability.

• Link: Google search box on website: Why is it suddenly much too large? - Q&A