Another method, which is somewhat less accessible because it relies on a newer technology, is to have hint text under or above the input, linked to the input via aria-describedby.
Code:
<label for="username">Username: </label>
<input name="username" id="username" aria-describedby="username_hint">
<p id="username_hint">Usernames are limited to letters, numbers and underscores. No spaces please.</p>
The p could be a span if your hint is really more of a fragment or you want your label-input pairs to sit next to an inline element.
Don't confuse aria-describedby with aria-labelledby (and note the spelling for that... that's TWO l's). Aria-labelledby will override your real label, which you generally don't want. You merely want your hint to be associated with the input.
Anyway, this method is not preferred over the text-in-the-label method above, which works with older browsers and Accessibility Technology (though I would have a space character between the label text and span text there, or you'll get "NameEnter your username..." read out), but having the hint text separate does allow you a bit more freedom in positioning, if you wanted the hint text right above or below the input, which is something I see commonly (also error messages).
Bookmarks