<label for="user-password">User Password</label>
<input type="password" id="user-password">
Rendered Output
<label for="user-password">User Password</label>
<input type="password" id="user-password" placeholder="10 characters max">
Rendered Output
<input type="password" placeholder="User Password">
Rendered Output
<label for="user-password">User Password</label>
<input type="password" id="user-password" value="mypass#123">
Rendered Output
<label for="user-password">User Password</label>
<input type="password" id="user-password" value="mypass#123" disabled>
Rendered Output Trying to enter or change the value has no effect.
<label for="user-password">User Password</label>
<input type="password" id="user-password" value="mypass#123" readonly>
Rendered Output Trying to enter or change the value has no effect.
<label for="user-password">User Password</label>

<!-- Limit input to a maximum of 10 characters with maxlength="10" -->
<input type="password" id="user-password" maxlength="10" placeholder="10 characters max">
Rendered Output
<form>
    <label for="pw">User Password</label>
    
    <!-- Require a minimum of 2 characters with minlength="2" -->
    <input type="password" id="pw" minlength="2" placeholder="Enter 2+ characters..." required>
    <button type="submit">Submit</button>
</form>
Rendered Output Practice Guide: Checking How minlength Works
  • Check for Errors: Leave the input field empty or enter only 1 character, then click the [Submit] button. Confirm that the browser displays an error message indicating that the minimum input requirement (2 characters) has not been met.
  • Check for Success: Enter 2 or more characters in the field, then click the [Submit] button again. Confirm that the form is submitted without an error.
<form>
    <fieldset>
        <legend>Password is required</legend>
        <p>
            <label for="username">Name</label>
            <input id="username" type="text">
        </p>
        <p>
            <label for="userpassword">Password (*required)</label>
            <!-- Specify as a required input field -->
            <input id="userpassword" type="password" required>
        </p>
        <p>
            <button type="submit">Submit</button>
        </p>
    </fieldset>
</form>
Rendered Output Practice Guide: Checking How required Works
  • Check for Errors: Without entering anything in the Password (*required) field, click the [Submit] button. Confirm that the browser displays an error message for the required field.
  • Check for Success: Enter a value in the Password (*required) field, then click the [Submit] button again. Confirm that the form is submitted without an error.
<input type="password" pattern="Specify a regular expression">
<p>
    <label>
        No size attribute
        <input type="password">
    </label>
</p>
<p>
    <label>
        Short input
        <input type="password" size="5">
    </label>
</p>
<p>
    <label>
        Long input
        <input type="password" size="50">
    </label>
</p>
Rendered Output
<label for="user-password">User Password</label>
<input type="password" id="user-password" value="12345" readonly>
<button type="button" id="toggle-password" onclick="togglePassword()">Show Password</button>

<script>
    function togglePassword() {
        const x = document.getElementById("user-password");
        const toggleButton = document.getElementById("toggle-password");
        
        if (x.type === "password") {
            x.type = "text";
            toggleButton.textContent = "Hide Password";
        } else {
            x.type = "password";
            toggleButton.textContent = "Show Password";
        }
    }
</script>
Rendered Output Click the "Password Visibility Toggle (Show/Hide)" button.