Topic 44 of 57 8. HTML Forms Interactive Tutorial

HTML Form Attributes: Complete List with Examples

12 mins read Last updated: 12 Nov 2026 16,500 views

Topic Overview & Definition

Key Question
What are the essential HTML attributes used to configure inputs and form behavior?
Direct Answer & Overview
HTML form attributes configure input constraints, usability behavior, and data submission. Key attributes include 'name' (parameter key), 'value' (initial content), 'placeholder' (ghost hint), 'required' (mandatory presence), 'disabled' (inactivated input), 'readonly' (uneditable input), 'autofocus' (cursor focus), and 'autocomplete' (browser autofill).

Comprehensive Step-by-Step Concepts

1) Identification and Submission: - name: The key submitted to the server in the HTTP request payload. - value: The actual data value stored inside the input. 2) Usability and User Guidance: - placeholder: Ghost text displaying an expected example format. Should never replace a visible

Runnable HTML5 Code Example & Practical Implementation

index.html
HTML Editor
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Form Attributes Showcase</title>
    <style>
        .control-row { margin-bottom: 12px; }
        label { display: block; font-weight: bold; margin-bottom: 4px; }
        input { padding: 8px 12px; width: 100%; max-width: 380px; border: 1px solid #cbd5e1; border-radius: 6px; }
        input:read-only { background: #f1f5f9; color: #64748b; }
    </style>
</head>
<body>
    <h2>Form Control Attributes Guide</h2>
    <form>
        <!-- Autofocus and Placeholder -->
        <div class="control-row">
            <label for="promoCode">Discount Promo Code</label>
            <input type="text" id="promoCode" name="promo_code" placeholder="SAVE20" maxlength="10" autofocus>
        </div>

        <!-- Readonly Reference ID (Submitted to server) -->
        <div class="control-row">
            <label for="orderRef">Order Reference Number (Readonly)</label>
            <input type="text" id="orderRef" name="order_ref" value="ORD-2026-90210" readonly>
        </div>

        <!-- Number constraints: min, max, step -->
        <div class="control-row">
            <label for="donationAmount">Custom Donation (USD)</label>
            <input type="number" id="donationAmount" name="donation" min="5.00" max="1000.00" step="0.50" value="25.00" required>
        </div>

        <!-- Multiple File Upload -->
        <div class="control-row">
            <label for="projectDocs">Upload Project Documents (Multiple)</label>
            <input type="file" id="projectDocs" name="documents[]" multiple accept=".pdf,.docx">
        </div>
    </form>
</body>
</html>

Key Takeaways, Best Practices & Standards

Best Practice & Standards
Never replace labels with placeholders, use autocomplete attributes for faster checkout/login, and apply min/max constraints.

Common Technical & Interview Questions

Q

Q1: What is the critical difference between the 'disabled' and 'readonly' attributes?

A1: Both prevent the user from editing the input. However, a 'disabled' input is greyed out, cannot receive focus, and is omitted from the form submission. A 'readonly' input can be focused, copied, and its value IS submitted to the server.
Q

Q2: Why should placeholder text never be used as a substitute for a

A2: Placeholders disappear as soon as the user begins typing (robbing the user of visual context), lack sufficient color contrast for accessibility, and are often ignored or poorly announced by screen readers.
Q

Q3: How does autocomplete="new-password" help password managers?

A3: It signals password managers (like Bitwarden, 1Password, or Chrome Password Manager) to generate a strong random password rather than suggesting an existing saved login.