is it autofocus="autofocus" or autofocus?

Darryl Hein picture Darryl Hein · Dec 15, 2010 · Viewed 53.5k times · Source

I seem to recall most (maybe all) attributes in previously versions of HTML (before HTML5) required attributes to have values, like readonly="readonly".

Is this true for HTML5 and the autofocus attribute?

Answer

Tim picture Tim · Dec 15, 2010

In HTML, you use boolean attributes with or without values as you like. A boolean, for W3C, like autofocus can be written like that autofocus or autofocus="autofocus" or also autofocus="".

If you don't want autofocus just don't write it.

I think you are confused because XHTML requires values for all attributes: attributes="values".

Here is some information about boolean attribute use in HTML: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attribute