HTML Search Box Generator

Create a custom HTML search box for your website instantly. Customize the style, colors, and text, then copy the ready-to-use HTML and CSS code.

px
px

Building a Search Box Without Writing Code

A search box is one of the most practical UI elements you can add to any website. Whether visitors are looking through blog posts, browsing products, or navigating a documentation site, a well-placed search box reduces friction and helps users find content faster. This generator lets you create a fully customized search box in seconds, without writing a single line of HTML or CSS by hand. Configure your preferred styles using the controls above, click Generate Code, and paste the output directly into your site.

Components of a Search Box

A standard HTML search box consists of three parts: a <form> wrapper that handles the submission logic, a <input type="search"> element where users type their query, and a <button type="submit"> that triggers the search. The form uses the GET method with the query parameter named q, which is the standard convention for search functionality. You can optionally add a search icon inside the input field to provide a visual cue for users. For more complete HTML form structures, our AI form generator builds entire forms with labels, validation, and multiple field types.

Customize Your Search Box

The generator above gives you full control over every visual property of your search box. You can change the placeholder text that appears inside the input before the user types, the label on the submit button, the border radius to make corners sharp or rounded, and the padding to control the input height. Color pickers let you set the background color, text color, button background, button text color, and border color independently. Checkboxes let you toggle a search icon, switch to a full pill/rounded style, enable full-width mode, or show and hide the border. For more advanced AI-powered HTML styling, use our AI CSS generator to extend or customize the styles further.

Customize Placeholder, Button, and Colors

The placeholder text and button label are the two pieces of copy that users read before interacting with the search box. Placeholder text appears inside the input field and disappears when the user starts typing. Use it to hint at what users can search for, such as "Search articles...", "Find a product...", or "Search documentation". The button label is what appears on the submit button. "Search" is the most common choice, but "Go", "Find", or "Explore" can match the tone of specific sites. These small copy decisions affect how approachable the search experience feels to users.

How to Generate a Custom Search Box in 5 Steps

1

Set Placeholder and Button Text

Enter the text that will appear inside the input field and on the submit button. These labels communicate the purpose of the search box to your visitors.

2

Choose Width and Spacing

Set the width of the search form in pixels or as a percentage of its container. Adjust padding to control the height of the input and button. Enable Full Width to span the entire container.

3

Pick Your Colors

Use the color pickers to set input background, text, button background, button text, and border colors. Match your website brand colors for a seamless fit.

4

Select Style Options

Toggle include icon to add a search magnifier inside the input. Check Rounded corners for a pill-shaped bar. Check Show border to add an outline.

5

Click Generate Code and Copy

Click the Generate Code button to produce the HTML and CSS. Copy each section separately or use Copy All, then paste into your website template or CMS.

Customization Options

Beyond basic styling, the generator includes a Form Action URL field. This is the URL your server-side search page lives at, such as /search or a full URL like https://example.com/search. When a user submits the form, the browser navigates to that URL with the query appended as ?q=their+search+term. If you leave this blank, the form will submit to the current page URL, which is useful if your CMS or framework handles search on the same page. You can also use the Create with AI tab on the left to describe a more specific search box and receive AI-generated HTML and CSS tailored to your requirements.

Responsive Search Bars for Any Website

A responsive search bar adapts its width to the screen size and container. The generated code uses display: flex on the form and flex: 1 on the input, so the input expands to fill available space while the button stays at a fixed width. Setting the form width to 100% or enabling Full Width in the generator ensures the search bar stretches across its parent container, which naturally scales across screen sizes. This layout approach works in sidebars, navigation bars, hero sections, and page content areas.

Website Navigation

Search boxes in navigation bars need to be compact but still functional. Set a width between 200px and 350px for a fixed inline navigation search, or use percentage-based width inside a flex nav container. A border radius of 6px to 8px looks clean and modern in most navigation designs. Keep padding low, around 8px to 10px, to maintain a slim appearance that fits alongside navigation links. If your navigation uses a dark background, set the input background to a slightly lighter dark tone and use white for text and placeholder, then match your brand accent color for the button.

Blog Search Functionality

Blog search boxes are often placed in sidebars or at the top of a blog index page. Use Full Width mode to span the sidebar column completely. A border radius of 8px to 12px with a visible border creates a clean, content-focused look appropriate for editorial sites. Set the form action to your blog platform's search URL. WordPress blogs typically use /?s= rather than ?q=, so you would need to update the input name attribute in the generated code from name="q" to name="s" if targeting a WordPress install. For comprehensive blog tooling, see our AI blog generator and blog title generator.

E-Commerce Product Search

Product search bars on e-commerce sites benefit from a prominent placement, often in the site header, and a design that stands out visually. Use a contrasting button color that matches your brand accent, a generous padding of 12px or more, and consider including the search icon to reinforce the input's purpose. For Shopify stores, the form action is /search with the parameter name="q", which the generator already sets by default. For more Shopify-specific tools, see our best AI tools for Shopify.

Adding Icons and Rounded Styles

Visual style choices significantly affect how a search box is perceived and used. The three most common search box styles are a simple rounded rectangle, a pill-shaped bar with fully rounded ends, and a box with an inline magnifier icon. Each serves different design contexts and user expectations. The generator supports all three through its options checkboxes, and you can combine them freely.

Simple Rounded Search Box

A simple rounded search box uses a border radius between 4px and 12px, which softens the corners without being overly stylized. This style fits most websites and frameworks, blends with standard form designs, and is easy to make consistent with other input fields and buttons on the page. Set border radius to 8px, show the border, and match the button background to your primary brand color for a clean, professional look. This is the default style the generator produces. For a complete HTML toolkit, our AI HTML generator can build out additional page components to pair with your new search bar.

Full-Width Search Bar

A full-width search bar spans 100% of its parent container. This style is popular in hero sections, section headers, and dedicated search pages where search is the primary action. Enable Full Width in the generator options to set the form width to 100% automatically. Combine this with generous padding and a contrasting button color to create a visually prominent search experience. Full-width search bars work particularly well in documentation sites and content repositories where users need to search frequently. The generated code uses flex: 1 on the input so it scales correctly inside any flex or block container.

Search Box with Icon

Adding a magnifier icon inside the input field provides a strong visual cue that the field is for searching. The icon is positioned absolutely inside a wrapper div, so it does not affect the input's text flow. The generator adds left padding automatically when the icon option is enabled, preventing the user's typed text from overlapping the icon. The icon color inherits from the input's text color setting, so it stays consistent as you change themes. Use this option on sites where the input might otherwise be mistaken for a generic text field, such as in sidebars or below article text where context is reduced. For more HTML tools, our free AI table generator HTML can help you build data tables to complement your search results page.

FAQ

How do I add a search box to my website?

Generate the HTML and CSS code using the tool above, then paste the HTML where you want the search box to appear in your page template, and add the CSS to your stylesheet. Set the form action URL to your website's search results page. For WordPress, the action is typically /?s= and the input name should be s. For most other platforms and custom setups, action is /search with name q.

Can I customize the colors?

Yes. The generator includes five separate color pickers: input background, input text, button background, button text, and border color. Each can be set independently using the standard color picker, which accepts any hex color value. Change any color and click Generate Code to update the CSS output.

Does it include JavaScript?

No. The generated search box uses only HTML and CSS. It relies on the browser's native form submission behavior, which sends a GET request to the form action URL with the search query as a URL parameter. If you need JavaScript-powered instant search or autocomplete, you would need to add a JavaScript library on top of the generated code.

How do I connect it to search?

Set the Form Action URL to your search endpoint. The input field uses name="q", so when the form is submitted, the browser navigates to your-action-url?q=search+term. Your server-side code reads the q parameter and returns the matching results.

Is the code responsive?

Yes. The form uses display: flex and the input uses flex: 1, so the input stretches to fill available space while the button stays fixed width. Setting the form to 100% width or enabling Full Width mode makes the search bar scale correctly on all screen sizes.

What is html search box?

An HTML search box is a form element on a web page that lets users type a query and submit it to a search endpoint. It typically consists of a form element, a text or search type input field, and a submit button. The query is passed to the server as a URL parameter when the form is submitted, and the server returns a results page.

What is search box for website?

A search box for a website is a UI component that enables site-wide or section-specific search. It is placed in headers, sidebars, hero sections, or inline within content. When a user types a term and submits, the search box passes the query to a search backend, which returns matching pages, posts, or products. It improves navigation and content discoverability, especially on sites with large amounts of content.

What is search button for website?

A search button for a website is the submit button paired with a search input field. It triggers the form submission that sends the user's query to the search endpoint. It can be labeled 'Search', 'Go', 'Find', or any word that fits the site's voice. Styling the search button to contrast with the input field draws attention to it and encourages users to submit their query.

What is web page search box?

A web page search box is the search input element embedded in a web page, as opposed to a browser's built-in search bar or a search engine's interface. It searches content within the specific website rather than the entire web. Web page search boxes are powered by server-side search logic, CMS search APIs, or third-party services like Algolia or Typesense. The HTML and CSS generated by this tool provides the front-end component that connects to any of those backends.

Related Tools