HTML 5 feature detection - required attribute on input fields - does it degrade gracefully?

424 Views Asked by At

I want to use the required attribute on one of my input fields. I have already coded in the JS version of it, but for completeness' sake, why not include the HTML 5 as well (at the very least save trouble for non JS users).

Is it safe to just add required to the input, it does it not degrade gracefully? If it doesn't, then how can I check for its support (without Modernizr)?

1

There are 1 best solutions below

2
On

If you're using <!DOCTYPE html> then there's no problem adding the required attribute.

You can feature detect using this JS:

'required' in document.createElement('input');