Belajar Input Type HTML5 Terbaru (email, number, range, date, dll)

Created at by Aris Munandar

HTML5 membawa revolusi besar dalam pengembangan form dengan memperkenalkan berbagai input type baru yang lebih spesifik dan powerful. Input type HTML5 tidak hanya mempermudah validasi data, tetapi juga meningkatkan user experience dengan menampilkan keyboard yang sesuai di perangkat mobile dan menyediakan UI picker yang intuitif. Artikel ini akan membahas secara lengkap semua input type HTML5 terbaru dengan contoh praktis dan implementasi yang efektif.

Baca juga: Cara Membuat Form Validation dengan HTML5

Mengapa Input Type HTML5 Penting?

Input type HTML5 memberikan banyak keuntungan untuk pengembangan website modern:

Manfaat Input Type HTML5

  • Validasi Bawaan: Validasi otomatis tanpa JavaScript tambahan
  • Mobile-Friendly: Keyboard yang sesuai muncul otomatis di perangkat mobile
  • User Experience: UI picker intuitif untuk date, time, color, dll
  • Accessibility: Lebih accessible untuk screen reader dan assistive technology
  • Semantic: Kode lebih bermakna dan mudah dipahami
  • Browser Support: Didukung oleh semua browser modern

1. Input Type Email

Input type email digunakan untuk input alamat email dengan validasi format otomatis.

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Input Type Email</title>
</head>
<body>
    <form action="/submit" method="post">
        <h2>Input Type Email</h2>
        
        <!-- Email basic -->
        <div class="form-group">
            <label for="email">Email</label>
            <input 
                type="email" 
                id="email" 
                name="email" 
                placeholder="nama@example.com"
                required
            >
        </div>

        <!-- Email dengan multiple -->
        <div class="form-group">
            <label for="emails">Multiple Emails</label>
            <input 
                type="email" 
                id="emails" 
                name="emails" 
                multiple
                placeholder="email1@example.com, email2@example.com"
            >
            <small>Pisahkan dengan koma untuk multiple email</small>
        </div>

        <!-- Email dengan pattern -->
        <div class="form-group">
            <label for="email-domain">Email Perusahaan</label>
            <input 
                type="email" 
                id="email-domain" 
                name="email_domain" 
                pattern="[a-z0-9._%+-]+@company\.com$"
                title="Harus menggunakan email @company.com"
                placeholder="nama@company.com"
                required
            >
        </div>

        <button type="submit">Submit</button>
    </form>
</body>
</html>Code language: HTML, XML (xml)

Keuntungan Input Type Email

  • Validasi format email otomatis
  • Keyboard email muncul di mobile (dengan @)
  • Autocomplete email dari browser
  • Mendukung multiple email addresses

2. Input Type Number

Input type number digunakan untuk input angka dengan kontrol increment/decrement.

<form action="/submit" method="post">
    <h2>Input Type Number</h2>
    
    <!-- Number basic -->
    <div class="form-group">
        <label for="quantity">Jumlah</label>
        <input 
            type="number" 
            id="quantity" 
            name="quantity" 
            min="1" 
            max="100" 
            value="1"
            required
        >
    </div>

    <!-- Number dengan step -->
    <div class="form-group">
        <label for="price">Harga</label>
        <input 
            type="number" 
            id="price" 
            name="price" 
            min="0" 
            step="0.01"
            placeholder="0.00"
            required
        >
        <small>Desimal diperbolehkan</small>
    </div>

    <!-- Number dengan step integer -->
    <div class="form-group">
        <label for="age">Usia</label>
        <input 
            type="number" 
            id="age" 
            name="age" 
            min="17" 
            max="100" 
            step="1"
            required
        >
    </div>

    <!-- Number tanpa spinner -->
    <div class="form-group">
        <label for="code">Kode</label>
        <input 
            type="number" 
            id="code" 
            name="code" 
            style="appearance: textfield;"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

Atribut Input Type Number

  • min: Nilai minimum yang diperbolehkan
  • max: Nilai maksimum yang diperbolehkan
  • step: Increment/decrement value (default: 1)
  • value: Nilai default

3. Input Type Range

Input type range menampilkan slider untuk memilih nilai dalam rentang tertentu.

<form action="/submit" method="post">
    <h2>Input Type Range</h2>
    
    <!-- Range basic -->
    <div class="form-group">
        <label for="volume">Volume</label>
        <input 
            type="range" 
            id="volume" 
            name="volume" 
            min="0" 
            max="100" 
            value="50"
        >
        <output for="volume">50</output>
    </div>

    <!-- Range dengan step -->
    <div class="form-group">
        <label for="rating">Rating (1-10)</label>
        <input 
            type="range" 
            id="rating" 
            name="rating" 
            min="1" 
            max="10" 
            step="1" 
            value="5"
            oninput="this.nextElementSibling.value = this.value"
        >
        <output>5</output>
    </div>

    <!-- Range dengan datalist -->
    <div class="form-group">
        <label for="brightness">Brightness</label>
        <input 
            type="range" 
            id="brightness" 
            name="brightness" 
            min="0" 
            max="100" 
            step="25" 
            list="brightness-levels"
        >
        <datalist id="brightness-levels">
            <option value="0" label="0%">
            <option value="25" label="25%">
            <option value="50" label="50%">
            <option value="75" label="75%">
            <option value="100" label="100%">
        </datalist>
    </div>

    <button type="submit">Submit</button>
</form>

<script>
    // Update output value dynamically
    const volumeInput = document.getElementById('volume');
    const volumeOutput = document.querySelector('output[for="volume"]');
    
    volumeInput.addEventListener('input', function() {
        volumeOutput.value = this.value;
    });
</script>Code language: HTML, XML (xml)

Styling Input Type Range

<style>
    input[type="range"] {
        width: 100%;
        height: 8px;
        border-radius: 5px;
        background: #ddd;
        outline: none;
    }

    input[type="range"]::-webkit-slider-thumb {
        appearance: none;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #667eea;
        cursor: pointer;
    }

    input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #667eea;
        cursor: pointer;
        border: none;
    }
</style>Code language: HTML, XML (xml)

4. Input Type Date

Input type date menampilkan date picker untuk memilih tanggal.

<form action="/submit" method="post">
    <h2>Input Type Date</h2>
    
    <!-- Date basic -->
    <div class="form-group">
        <label for="birthdate">Tanggal Lahir</label>
        <input 
            type="date" 
            id="birthdate" 
            name="birthdate" 
            required
        >
    </div>

    <!-- Date dengan min dan max -->
    <div class="form-group">
        <label for="reservation">Tanggal Reservasi</label>
        <input 
            type="date" 
            id="reservation" 
            name="reservation" 
            min="2024-10-15" 
            max="2024-12-31"
            required
        >
        <small>Reservasi hanya tersedia hingga akhir tahun</small>
    </div>

    <!-- Date dengan value default -->
    <div class="form-group">
        <label for="start-date">Tanggal Mulai</label>
        <input 
            type="date" 
            id="start-date" 
            name="start_date" 
            value="2024-10-15"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

5. Input Type Time

Input type time untuk memilih waktu dengan format 24 jam.

<form action="/submit" method="post">
    <h2>Input Type Time</h2>
    
    <!-- Time basic -->
    <div class="form-group">
        <label for="meeting-time">Waktu Meeting</label>
        <input 
            type="time" 
            id="meeting-time" 
            name="meeting_time" 
            required
        >
    </div>

    <!-- Time dengan min dan max -->
    <div class="form-group">
        <label for="work-time">Jam Kerja</label>
        <input 
            type="time" 
            id="work-time" 
            name="work_time" 
            min="08:00" 
            max="17:00"
            required
        >
        <small>Jam kerja: 08:00 - 17:00</small>
    </div>

    <!-- Time dengan step (seconds) -->
    <div class="form-group">
        <label for="precise-time">Waktu Presisi</label>
        <input 
            type="time" 
            id="precise-time" 
            name="precise_time" 
            step="1"
        >
        <small>Termasuk detik</small>
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

6. Input Type Datetime-Local

Input type datetime-local untuk memilih tanggal dan waktu lokal.

<form action="/submit" method="post">
    <h2>Input Type Datetime-Local</h2>
    
    <!-- Datetime-local basic -->
    <div class="form-group">
        <label for="appointment">Jadwal Appointment</label>
        <input 
            type="datetime-local" 
            id="appointment" 
            name="appointment" 
            required
        >
    </div>

    <!-- Datetime-local dengan min -->
    <div class="form-group">
        <label for="event-time">Waktu Event</label>
        <input 
            type="datetime-local" 
            id="event-time" 
            name="event_time" 
            min="2024-10-15T00:00"
            required
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

7. Input Type Week

Input type week untuk memilih minggu dalam tahun.

<form action="/submit" method="post">
    <h2>Input Type Week</h2>
    
    <div class="form-group">
        <label for="week-select">Pilih Minggu</label>
        <input 
            type="week" 
            id="week-select" 
            name="week" 
            required
        >
    </div>

    <div class="form-group">
        <label for="work-week">Minggu Kerja</label>
        <input 
            type="week" 
            id="work-week" 
            name="work_week" 
            min="2024-W01" 
            max="2024-W52"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

8. Input Type Month

Input type month untuk memilih bulan dan tahun.

<form action="/submit" method="post">
    <h2>Input Type Month</h2>
    
    <div class="form-group">
        <label for="birth-month">Bulan Lahir</label>
        <input 
            type="month" 
            id="birth-month" 
            name="birth_month" 
            required
        >
    </div>

    <div class="form-group">
        <label for="report-month">Bulan Laporan</label>
        <input 
            type="month" 
            id="report-month" 
            name="report_month" 
            min="2024-01" 
            max="2024-12"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

9. Input Type Color

Input type color menampilkan color picker untuk memilih warna.

<form action="/submit" method="post">
    <h2>Input Type Color</h2>
    
    <!-- Color basic -->
    <div class="form-group">
        <label for="favorite-color">Warna Favorit</label>
        <input 
            type="color" 
            id="favorite-color" 
            name="favorite_color" 
            value="#3498db"
        >
    </div>

    <!-- Color untuk theme -->
    <div class="form-group">
        <label for="theme-color">Warna Theme</label>
        <input 
            type="color" 
            id="theme-color" 
            name="theme_color" 
            value="#667eea"
            onchange="document.body.style.backgroundColor = this.value"
        >
        <small>Pilih warna untuk mengubah background</small>
    </div>

    <!-- Multiple color inputs -->
    <div class="form-group">
        <label for="primary-color">Primary Color</label>
        <input 
            type="color" 
            id="primary-color" 
            name="primary_color" 
            value="#667eea"
        >
    </div>

    <div class="form-group">
        <label for="secondary-color">Secondary Color</label>
        <input 
            type="color" 
            id="secondary-color" 
            name="secondary_color" 
            value="#764ba2"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

10. Input Type Tel

Input type tel untuk input nomor telepon dengan keyboard telepon di mobile.

<form action="/submit" method="post">
    <h2>Input Type Tel</h2>
    
    <!-- Tel basic -->
    <div class="form-group">
        <label for="phone">Nomor Telepon</label>
        <input 
            type="tel" 
            id="phone" 
            name="phone" 
            placeholder="08123456789"
            required
        >
    </div>

    <!-- Tel dengan pattern -->
    <div class="form-group">
        <label for="mobile">Nomor HP</label>
        <input 
            type="tel" 
            id="mobile" 
            name="mobile" 
            pattern="[0-9]{10,13}"
            placeholder="08123456789"
            title="Nomor telepon harus 10-13 digit"
            required
        >
    </div>

    <!-- Tel dengan format internasional -->
    <div class="form-group">
        <label for="intl-phone">Telepon Internasional</label>
        <input 
            type="tel" 
            id="intl-phone" 
            name="intl_phone" 
            pattern="^\+[0-9]{1,3}[0-9]{4,14}$"
            placeholder="+6281234567890"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

11. Input Type URL

Input type url untuk input alamat website dengan validasi format URL.

<form action="/submit" method="post">
    <h2>Input Type URL</h2>
    
    <!-- URL basic -->
    <div class="form-group">
        <label for="website">Website</label>
        <input 
            type="url" 
            id="website" 
            name="website" 
            placeholder="https://example.com"
            required
        >
    </div>

    <!-- URL dengan pattern -->
    <div class="form-group">
        <label for="portfolio">Portfolio URL</label>
        <input 
            type="url" 
            id="portfolio" 
            name="portfolio" 
            pattern="https://.*"
            placeholder="https://portfolio.com"
            title="URL harus dimulai dengan https://"
        >
    </div>

    <!-- Multiple URLs -->
    <div class="form-group">
        <label for="social-links">Social Media Links</label>
        <input 
            type="url" 
            id="social-links" 
            name="social_links" 
            multiple
            placeholder="https://facebook.com/user, https://twitter.com/user"
        >
    </div>

    <button type="submit">Submit</button>
</form>Code language: HTML, XML (xml)

Input type search untuk search box dengan tombol clear bawaan.

<form action="/search" method="get">
    <h2>Input Type Search</h2>
    
    <!-- Search basic -->
    <div class="form-group">
        <label for="search">Cari</label>
        <input 
            type="search" 
            id="search" 
            name="q" 
            placeholder="Cari artikel..."
        >
    </div>

    <!-- Search dengan autocomplete -->
    <div class="form-group">
        <label for="product-search">Cari Produk</label>
        <input 
            type="search" 
            id="product-search" 
            name="product" 
            list="products"
            placeholder="Ketik nama produk..."
        >
        <datalist id="products">
            <option value="Laptop">
            <option value="Smartphone">
            <option value="Tablet">
            <option value="Smartwatch">
        </datalist>
    </div>

    <button type="submit">Cari</button>
</form>Code language: HTML, XML (xml)

13. Input Type File

Input type file untuk upload file dengan berbagai atribut.

<form action="/upload" method="post" enctype="multipart/form-data">
    <h2>Input Type File</h2>
    
    <!-- File basic -->
    <div class="form-group">
        <label for="document">Upload Dokumen</label>
        <input 
            type="file" 
            id="document" 
            name="document" 
            required
        >
    </div>

    <!-- File dengan accept -->
    <div class="form-group">
        <label for="image">Upload Gambar</label>
        <input 
            type="file" 
            id="image" 
            name="image" 
            accept="image/*"
            required
        >
    </div>

    <!-- File dengan accept spesifik -->
    <div class="form-group">
        <label for="pdf">Upload PDF</label>
        <input 
            type="file" 
            id="pdf" 
            name="pdf" 
            accept=".pdf"
        >
    </div>

    <!-- Multiple files -->
    <div class="form-group">
        <label for="photos">Upload Multiple Photos</label>
        <input 
            type="file" 
            id="photos" 
            name="photos" 
            accept="image/*" 
            multiple
        >
    </div>

    <button type="submit">Upload</button>
</form>Code language: HTML, XML (xml)

Contoh Form Lengkap dengan Semua Input Type HTML5

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Form HTML5 Lengkap</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 20px;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #555;
            font-weight: 500;
        }

        input, textarea, select {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        input:focus {
            outline: none;
            border-color: #667eea;
        }

        button {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
        }

        button:hover {
            transform: translateY(-2px);
        }

        small {
            display: block;
            margin-top: 5px;
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Form HTML5 Lengkap</h1>
        <form action="/submit" method="post">
            <div class="form-group">
                <label for="email">Email</label>
                <input type="email" id="email" name="email" required>
            </div>

            <div class="form-group">
                <label for="age">Usia</label>
                <input type="number" id="age" name="age" min="17" max="100" required>
            </div>

            <div class="form-group">
                <label for="rating">Rating</label>
                <input type="range" id="rating" name="rating" min="1" max="10" value="5">
            </div>

            <div class="form-group">
                <label for="birthdate">Tanggal Lahir</label>
                <input type="date" id="birthdate" name="birthdate" required>
            </div>

            <div class="form-group">
                <label for="time">Waktu</label>
                <input type="time" id="time" name="time" required>
            </div>

            <div class="form-group">
                <label for="color">Warna Favorit</label>
                <input type="color" id="color" name="color" value="#667eea">
            </div>

            <div class="form-group">
                <label for="phone">Telepon</label>
                <input type="tel" id="phone" name="phone" pattern="[0-9]{10,13}" required>
            </div>

            <div class="form-group">
                <label for="website">Website</label>
                <input type="url" id="website" name="website" placeholder="https://example.com">
            </div>

            <button type="submit">Submit Form</button>
        </form>
    </div>
</body>
</html>Code language: HTML, XML (xml)

Dari kode diatas maka akan menghasilkan tampilkan seperti gambar di bawah ini.

Form input lengkap HTML5

Browser Support Input Type HTML5

Input TypeChromeFirefoxSafariEdge
email
number
range
date
time
datetime-local
week
month
color
tel
url
search

Best Practice Input Type HTML5

1. Gunakan Input Type yang Sesuai

Selalu gunakan input type yang paling sesuai dengan data yang diharapkan untuk mendapatkan validasi dan UX terbaik.

2. Tambahkan Placeholder dan Label

<label for="email">Email</label>
<input 
    type="email" 
    id="email" 
    placeholder="nama@example.com"
    required
>Code language: HTML, XML (xml)

3. Kombinasikan dengan Atribut Validasi

<input 
    type="number" 
    min="1" 
    max="100" 
    step="1" 
    required
>Code language: HTML, XML (xml)

4. Berikan Feedback yang Jelas

<input type="tel" pattern="[0-9]{10,13}" title="Nomor telepon harus 10-13 digit">
<small>Format: 08123456789</small>Code language: HTML, XML (xml)

Kesimpulan

Input type HTML5 adalah fitur powerful yang sangat meningkatkan user experience dan mempermudah validasi form. Dengan memahami dan menggunakan input type yang tepat seperti email, number, range, date, time, color, tel, url, dan lainnya, Anda dapat membuat form yang lebih intuitif, mobile-friendly, dan user-friendly.

Setiap input type HTML5 memiliki karakteristik dan kegunaan spesifik yang harus dipahami untuk implementasi yang optimal. Mulai gunakan input type HTML5 dalam project Anda untuk menciptakan form yang modern dan efektif.

1 HTML Dasar (Pemula)

2 HTML Menengah

4 HTML Mahir

5 HTML Ahli (Bonus & Tips)

Comments

Congrats, you have the opportunity to be the first commenter on this article. Have questions or suggestions? Please leave a comment to start discussion.

Leave comment

Alamat email Anda tidak akan dipublikasikan. Required fields are marked *

news-1701

sabung ayam online

yakinjp

yakinjp

rtp yakinjp

slot thailand

yakinjp

yakinjp

yakin jp

yakinjp id

maujp

maujp

maujp

maujp

sabung ayam online

sabung ayam online

judi bola online

sabung ayam online

judi bola online

slot mahjong ways

slot mahjong

sabung ayam online

judi bola

live casino

sabung ayam online

judi bola

live casino

SGP Pools

slot mahjong

sabung ayam online

slot mahjong

SLOT THAILAND

138000491

138000492

138000493

138000494

138000495

138000496

138000497

138000498

138000499

138000500

138000501

138000502

138000503

138000504

138000505

138000506

138000507

138000508

138000509

138000510

138000511

138000512

138000513

138000514

138000515

138000516

138000517

138000518

138000519

138000520

138000521

138000522

138000523

138000524

138000525

article 138000526

article 138000527

article 138000528

article 138000529

article 138000530

article 138000531

article 138000532

article 138000533

article 138000534

article 138000535

article 138000536

article 138000537

article 138000538

article 138000539

article 138000540

article 138000541

article 138000542

article 138000543

article 138000544

article 138000545

article 138000546

article 138000547

article 138000548

article 138000549

article 138000550

article 138000551

article 138000552

article 138000553

article 138000554

article 138000555

158000396

158000397

158000398

158000399

158000400

158000401

158000402

158000403

158000404

158000405

158000406

158000407

158000408

158000409

158000410

158000411

158000412

158000413

158000414

158000415

article 158000416

article 158000417

article 158000418

article 158000419

article 158000420

article 158000421

article 158000422

article 158000423

article 158000424

article 158000425

article 158000426

article 158000427

article 158000428

article 158000429

article 158000430

article 158000431

article 158000432

article 158000433

article 158000434

article 158000435

208000411

208000412

208000413

208000414

208000415

208000416

208000417

208000418

208000419

208000420

208000421

208000422

208000423

208000424

208000425

208000426

208000427

208000428

208000429

208000430

208000431

208000432

208000433

208000434

208000435

article 208000436

article 208000437

article 208000438

article 208000439

article 208000440

article 208000441

article 208000442

article 208000443

article 208000444

article 208000445

article 208000446

article 208000447

article 208000448

article 208000449

article 208000450

article 208000451

article 208000452

article 208000453

article 208000454

article 208000455

article 208000456

article 208000457

article 208000458

article 208000459

article 208000460

article 208000461

article 208000462

article 208000463

article 208000464

article 208000465

208000436

208000437

208000438

208000439

208000440

208000441

208000442

208000443

208000444

208000445

208000446

208000447

208000448

208000449

208000450

208000451

208000452

208000453

208000454

208000455

228000271

228000272

228000273

228000274

228000275

228000276

228000277

228000278

228000279

228000280

228000281

228000282

228000283

228000284

228000285

article 228000286

article 228000287

article 228000288

article 228000289

article 228000290

article 228000291

article 228000292

article 228000293

article 228000294

article 228000295

article 228000296

article 228000297

article 228000298

article 228000299

article 228000300

article 228000301

article 228000302

article 228000303

article 228000304

article 228000305

article 228000306

article 228000307

article 228000308

article 228000309

article 228000310

article 228000311

article 228000312

article 228000313

article 228000314

article 228000315

238000241

238000242

238000243

238000244

238000245

238000246

238000247

238000248

238000249

238000250

238000251

238000252

238000254

238000255

238000256

238000257

238000258

238000259

238000260

article 238000261

article 238000262

article 238000263

article 238000264

article 238000265

article 238000266

article 238000267

article 238000268

article 238000269

article 238000270

article 238000271

article 238000272

article 238000273

article 238000274

article 238000275

article 238000276

article 238000277

article 238000278

article 238000279

article 238000280

news-1701