HTML, CSS, Forms - A Test

When using ::placeholder in connection with the attribute of the same name ( placeholder="your text" ) being put in an input field, we can tell our users what or how they should fill an input field in our precious webforms.

On top of that we love to tell people which fields they have to fill out in order to be able to submit said webform to us. Therefore we got the :required pseudo-class to style form elements which we deem important – you sure want to write required into the input then for the styling to take effect. <input required /> will do by the way, as it is a boolean and therefore it defaults to true when it's there.

I think I found a nice way to combine both the pesudo-element with the pseudo-class in order to give people a hint on required fields.

Notice: Browser Support is an issue when it comes to IE. "&#$§¥ you IE!." Anything lower than IE10 won't understand those selectors. *shakes fist towards the sky*

Enough with the chatter, here we go with the example form:


Please tell me a few things about you! Required fields are marked with a blue border.

Interestingly enough the placeholder text for <input type="number" /> does not change its color although the field is set to required in the HTML. The border color though did change.

Update:

Now, that I added the :valid and :invalid selectors to the CSS, there's another funky thing going on. The <number> input is now marked as invalid although it's empty (apart from the placeholder, which now received the color I set for invalid input values). STRRRRAAAAANNNGE!

Apart from that you would have to know Regular Expressions in order to prevent the type="text" inputs to take any character. You'd want to prevent people from using numbers for their name, right? There might be a use-case for this (numbers in names that is) but I honestly don't know, so I'd go the way of not preventing the user from typing whatever he thinks his name really is. - Yours Batman1982-0H-Y34H

Interesting find: When setting the submit button styles related to the form being valid or invalid you can give users visible feedback on whether they can submit the form or not.