Docs/HTML/Forms

HTML Forms

Forms digunakan untuk mengumpulkan input dari pengguna. Elemen utama:

  • <form> — container form
  • <input> — berbagai jenis input
  • <textarea> — input teks panjang
  • <select> — dropdown menu
  • <button> — tombol submit
  • <label> — label untuk input (penting untuk aksesibilitas)

Atribut Form

  • action — URL tujuan pengiriman data
  • method — GET atau POST
  • enctype — tipe encoding (penting untuk file upload)
index.html
Try It →
<form>
  <div>
    <label>Name:</label><br>
    <input type="text" placeholder="Your name">
  </div>
  <div>
    <label>Email:</label><br>
    <input type="email" placeholder="you@example.com">
  </div>
  <div>
    <label>Language:</label><br>
    <select>
      <option>HTML</option>
      <option>CSS</option>
      <option>JavaScript</option>
      <option>PHP</option>
    </select>
  </div>
  <div>
    <label>Message:</label><br>
    <textarea rows="3" placeholder="Your message..."></textarea>
  </div>
  <button type="button">Submit</button>
</form>