본문 바로가기
명함 만들기 캐릭터 모음 16가지 디자인 · PNG / SVG / PDF

검색창

목록이 길어 찾는 편이 훑어보는 편보다 빠를 때 — 무엇으로 찾을 수 있는지 자리표시자가 말해 준다.

입력

실제 미리보기

출처

<form class="dc-srch" role="search" action="#">
  <label class="dc-sr" for="dc-srch-q">상품 검색</label>
  <span class="dc-srch__field">
    <span class="dc-srch__icon" aria-hidden="true"><svg viewBox="0 0 20 20" width="18" height="18" focusable="false"><circle cx="9" cy="9" r="6" fill="none" stroke="currentColor" stroke-width="2" /><path d="M13.5 13.5 18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" /></svg></span>
    <input class="dc-srch__input" id="dc-srch-q" type="search" name="q" placeholder="상품명, 주문번호로 검색" autocomplete="off">
  </span>
  <button class="dc-srch__submit" type="submit">검색</button>
</form>
.dc-srch {
  position: relative; display: flex; align-items: center; gap: var(--dc-2);
  max-width: 460px; font-family: var(--dc-font);
}
.dc-srch__field {
  position: relative; display: flex; align-items: center; flex: 1 1 auto;
  min-width: 0; min-height: 44px;
  border: 1px solid var(--dc-line-field); border-radius: var(--dc-r-full);
  background: var(--dc-surface);
  transition: border-color var(--dc-fast), box-shadow var(--dc-fast);
}
.dc-srch__field:hover { border-color: var(--dc-line-bold); }
.dc-srch__field:focus-within {
  border-color: var(--dc-brand); box-shadow: 0 0 0 3px var(--dc-brand-soft);
}
.dc-srch__icon {
  flex: none; display: inline-flex; padding-left: var(--dc-3);
  color: var(--dc-text-sub);
}
.dc-srch__input {
  appearance: none; -webkit-appearance: none;
  flex: 1 1 auto; min-width: 0;
  min-height: 42px; padding: 0 var(--dc-2);
  border: 0; background: none; color: var(--dc-text);
  font-family: inherit; font-size: 15px; line-height: 1.4;
}
.dc-srch__input::placeholder { color: var(--dc-text-mute); }
.dc-srch__input:focus { outline: none; }
.dc-srch__input::-webkit-search-cancel-button { display: none; }
.dc-srch__clear {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border: 0; border-radius: var(--dc-r-full);
  background: none; color: var(--dc-text-sub);
  transition: color var(--dc-fast), background var(--dc-fast);
}
.dc-srch__clear:hover { color: var(--dc-text); background: var(--dc-sunken); }
.dc-srch__submit {
  flex: none; min-height: 44px; padding: 0 var(--dc-5);
  border: 1px solid transparent; border-radius: var(--dc-r-full);
  background: var(--dc-brand); color: var(--dc-text-on);
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1;
  white-space: nowrap;
}
.dc-srch__submit:hover { background: var(--dc-brand-hi); }
.dc-srch__list {
  position: absolute; top: calc(100% + var(--dc-2)); left: 0; right: 0; z-index: 2;
  margin: 0; padding: var(--dc-1); list-style: none;
  border: 1px solid var(--dc-line); border-radius: var(--dc-r-md);
  background: var(--dc-surface); box-shadow: var(--dc-sh-2);
}
.dc-srch__opt {
  display: flex; align-items: center; gap: var(--dc-2);
  min-height: 40px; padding: 0 var(--dc-3); border-radius: var(--dc-r-sm);
  font-size: 14px; color: var(--dc-text); cursor: pointer;
}
.dc-srch__opt:hover,
.dc-srch__opt[aria-selected="true"] { background: var(--dc-brand-soft); color: var(--dc-brand-text); }
.dc-srch__hint { margin-left: auto; font-size: 13px; color: var(--dc-text-sub); }
.dc-srch--compact .dc-srch__field { min-height: 36px; }
.dc-srch--compact .dc-srch__input { min-height: 34px; font-size: 14px; }

이렇게 씁니다

  • 자리표시자에 검색되는 것을 적는다: "상품명, 주문번호로 검색"처럼
  • 입력이 있으면 지우기 버튼을 띄운다 — 모바일에서 백스페이스를 길게 누르게 하지 않는다
  • 결과가 즉시 갱신되면 검색 버튼을 빼고, 서버로 넘겨 페이지가 바뀌면 버튼을 둔다

주의할 점

  • role="search" 와 label 을 빼면 스크린리더에게는 이름 없는 입력칸일 뿐이다
  • 추천 목록을 띄울 때는 aria-expanded 와 방향키 이동을 함께 만들어야 한다

다음에 볼 것