Course contentsShow
← Web Development
Lesson 106 of 2,9822. HTML FundamentalsFree lesson

Placeholder and Autocomplete Attributes

Providing input hints with placeholder text and controlling browser autofill behavior.

Placeholder and Autocomplete Attributes

What you'll learn: How to provide helpful hints inside form inputs and control whether browsers should offer to autofill values.

When users face an empty form field, they sometimes need a little guidance about what to enter. That's where these two attributes come in—they make forms friendlier and faster to complete.

The placeholder Attribute

The placeholder attribute displays light gray text inside an input field that disappears as soon as the user starts typing. Think of it like a Post-it note inside the field that says "here's an example of what goes here."

<input type="email" placeholder="you@example.com">
<input type="tel" placeholder="(555) 123-4567">
<textarea placeholder="Tell us your thoughts..."></textarea>

Important: Placeholders are hints, not labels. They disappear when typing begins, so they shouldn't contain critical information. Always use a proper <label> element for important instructions.

The autocomplete Attribute

Modern browsers remember information you've entered before and offer to fill it in automatically. The autocomplete attribute lets you control this behavior:

<!-- Let the browser help with standard fields -->
<input type="email" name="email" autocomplete="email">
<input type="tel" name="phone" autocomplete="tel">

<!-- Turn off autocomplete for sensitive fields -->
<input type="text" name="code" autocomplete="off">

You can use specific values like "name", "email", "street-address", "postal-code", or simply "on" (default) and "off". Proper autocomplete values help browsers fill forms accurately and assist users with disabilities.

Key Takeaway: Use placeholder to show input examples (but never replace labels), and use autocomplete to help browsers intelligently fill fields or disable autofill for sensitive information.