# Search with Category

> A marketplace search bar that joins a category select, a search field and a search button into one pill.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: search, category, select, marketplace, input group, button
- Live preview: https://copy-css.com/snippets/category-search-bar
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<form class="cat-search" role="search">
  <select name="cat" aria-label="Category">
    <option>All</option>
    <option>Books</option>
    <option>Music</option>
  </select>
  <input type="search" name="q" placeholder="Search products" aria-label="Search products">
  <button type="submit" aria-label="Search">
    <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
  </button>
</form>
```

## CSS

```css
.cat-search {
  display: flex;
  width: 100%;
  max-width: 320px;
  overflow: hidden;
  border: 2px solid #f97316;
  border-radius: 12px;
  background: #fff;
  font-family: system-ui, sans-serif;
}

.cat-search:focus-within {
  box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.2);
}

.cat-search select {
  padding: 0 24px 0 12px;
  border: 0;
  border-right: 1px solid #fed7aa;
  background: #fff7ed url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a3412' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 10px;
  color: #7c2d12;
  font: 600 13px system-ui, sans-serif;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.cat-search input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: #1c1917;
  font: 15px system-ui, sans-serif;
}

.cat-search button {
  display: grid;
  place-items: center;
  width: 46px;
  border: 0;
  background: #f97316;
  color: #fff;
  cursor: pointer;
}

.cat-search button:hover {
  background: #ea580c;
}

.cat-search svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.cat-search select:focus-visible,
.cat-search input:focus-visible,
.cat-search button:focus-visible {
  outline: 2px solid #9a3412;
  outline-offset: -3px;
}
```

## Notes

- This CSS Search with Category is 66 lines of pure CSS (1.4 KB) with no JavaScript and no dependencies. It uses box shadows, CSS Grid, Flexbox and keyboard focus styles.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
