본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Tailwind CSS 파일 입력 (File Input)

원문 보기 위키 갱신

파일 입력 컴포넌트는 사용자의 기기 저장소에서 하나 이상의 파일을 업로드할 수 있게 해줘요. 여러 크기와 스타일, 변형을 제공하며 Tailwind CSS의 유틸리티 우선 클래스로 만들어져 있어 다크 모드까지 지원해요.

파일 입력 컴포넌트에 필요한 모든 스타일을 적용하려면 Tailwind CSS 프로젝트에 Flowbite를 플러그인으로 포함해 두어야 해요.

출처: 문서

본문

파일 업로드 예시

사용자가 단일 파일을 업로드할 수 있는 간단한 파일 입력 컴포넌트부터 시작해 볼게요.

<label class="block mb-2.5 text-sm font-medium text-heading" for="file_input">Upload file</label>
<input class="cursor-pointer bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand block w-full shadow-xs placeholder:text-body" id="file_input" type="file">

도움말 텍스트를 추가하려면 aria-describedby 속성으로 안내 문구를 붙여주면 돼요.

<label class="block mb-2.5 text-sm font-medium text-heading" for="file_input">Upload file</label>
<input class="cursor-pointer bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand block w-full shadow-xs placeholder:text-body" aria-describedby="file_input_help" id="file_input" type="file">
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300" id="file_input_help">SVG, PNG, JPG or GIF (MAX. 800x400px).</p>

여러 파일을 한 번에 업로드하려면 multiple 속성을 추가하면 돼요.

<label class="block mb-2.5 text-sm font-medium text-heading" for="multiple_files">Upload multiple files</label>
<input class="cursor-pointer bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand block w-full shadow-xs placeholder:text-body" id="multiple_files" type="file" multiple>

text-sm/text-lg 클래스를 바꾸면 기본 크기와 큰 크기를 선택할 수 있어요.

<label class="block mb-2.5 text-sm font-medium text-heading" for="small_size">Base file input</label>
<input class="cursor-pointer bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base focus:ring-brand focus:border-brand block w-full shadow-xs placeholder:text-body" id="small_size" type="file">

<label class="block mb-2.5 text-sm font-medium text-heading" for="large_size">Large file input</label>
<input class="cursor-pointer bg-neutral-secondary-medium border border-default-medium text-heading text-lg rounded-base focus:ring-brand focus:border-brand block w-full shadow-xs placeholder:text-body" id="large_size" type="file">

드래그 앤 드롭 존(drag and drop zone) 스타일의 예시도 준비되어 있어요.

<div class="flex items-center justify-center w-full">
    <label for="dropzone-file" class="flex flex-col items-center justify-center w-full h-64 bg-neutral-secondary-medium border border-dashed border-default-strong rounded-base cursor-pointer hover:bg-neutral-tertiary-medium">
        <div class="flex flex-col items-center justify-center text-body pt-5 pb-6">
            <svg class="w-8 h-8 mb-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h3a3 3 0 0 0 0-6h-.025a5.56 5.56 0 0 0 .025-.5A5.5 5.5 0 0 0 7.207 9.021C7.137 9.017 7.071 9 7 9a4 4 0 1 0 0 8h2.167M12 19v-9m0 0-2 2m2-2 2 2"/></svg>
            <p class="mb-2 text-sm"><span class="font-semibold">Click to upload</span> or drag and drop</p>
            <p class="text-xs">SVG, PNG, JPG or GIF (MAX. 800x400px)</p>
        </div>
        <input id="dropzone-file" type="file" class="hidden" />
    </label>
</div>

업로드 버튼으로 파일 선택을 트리거하는 방식도 지원해요.

<div class="flex items-center justify-center w-full">
  <div class="flex flex-col items-center justify-center w-full h-64 bg-neutral-secondary-medium border border-dashed border-default-strong rounded-base">
    <div class="flex flex-col items-center justify-center text-body pt-5 pb-6">
      <svg class="w-8 h-8 mb-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v9m-5 0H5a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1h-2M8 9l4-5 4 5m1 8h.01"/></svg>
      <p class="mb-2 text-sm">Click the button below to upload</p>
      <p class="text-xs mb-4">Max. File Size: <span class="font-semibold">30MB</span></p>
      <!-- Upload Button -->
      <button type="button" onclick="document.getElementById('dropzone-file-2').click()" class="inline-flex items-center text-white bg-brand hover:bg-brand-strong box-border border border-transparent focus:ring-4 focus:ring-brand-medium shadow-xs font-medium leading-5 rounded-base text-sm px-3 py-2 focus:outline-none">
        <svg class="w-4 h-4 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="m21 21-3.5-3.5M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z"/></svg>
        Browse file
      </button>
    </div>
  </div>
  <!-- Hidden File Input (Outside Label) -->
  <input id="dropzone-file-2" type="file" class="hidden" />
</div>

더 알아보기 (Learn more)

  • File Input 문서 (공식)
  • 단일/다중 업로드, 도움말 텍스트, 크기 변형, 드래그 앤 드롭 존 등 다양한 형태로 활용할 수 있어요.