Am I right in saying required is an empty attribute and doesn't require a value but xHTML prefers that it has one to be complete. Seems to work fine without ="required" on all pages I've created, I just wondered if perhaps certain browsers interpret them differently.
Definition and Usage The required attribute is a boolean attribute. When present, it specifies that an input field must be filled out before submitting the form. Note: The required attribute works with the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.
It can be added to form fields just like aria-required=”true” and it's supposed to alert screen reader users that the field is required. However, where HTML 5 required differs from aria-required=”true” is that HTML 5 required actually has behavior associated with it.
If the input elements aren't inside a form tag then HTML5 required attribute will fail to work. So always put input tags inside a form along with the form encapsulation itself.
jsFiddle Demo
There is no difference from a rendering perspective. But if you are going to be looking in the future for these required elements, it helps to have a value to test for.
Required
This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The :optional and :required CSS pseudo-classes will be applied to the field as appropriate. MDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With