Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

required or required = "required"

Tags:

html

required

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.

like image 987
Crouch Avatar asked Sep 24 '13 13:09

Crouch


People also ask

What is required required in HTML?

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.

What is the difference between required and Aria required?

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.

Why required attribute is not working?

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.


1 Answers

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

like image 56
Travis J Avatar answered Oct 07 '22 10:10

Travis J