One day I’ll get around to properly documenting this, but see this example: http://dorward.me.uk/tmp/label-work/example.html
In short — position a <label>
under a transparent <input>
using <div>
to provide background colour and borders.
Then use JS to determine if the label should be visible or not based on focusing.
Apply different styles when JS is not available to position the label beside the element instead.
Unlike using the value
, this doesn’t render the content inaccessible to devices which only display the focused content (e.g. screen readers), and also works for inputs of the password
type.