Required attributes for HTML5 image input

Posted in HTML and CSS -

I recently validated an HTML 5 page using the W3C validator service and was surprised to discover which attributes are required (and not required) for an image input. Note that of course the HTML5 specification is still under development at the time of this post so is subject to change.

What is required

If the input is empty then this validates just fine:

<input>

As soon as type="image" is added to the <input> some attributes become required.

I first tried validating some HTML that looked more or less like this:

<input id="myid" type="image" src="myfile.gif">

and got the error message:

Required attributes missing on element input.

Unfortunately the validator does not specify which attribute are required, instead just listing a whole bunch of attributes that are valid. I eventually managed to work out that it's only the "alt" attribute that is required. Surprisingly for an input type="image" the "src" attribute is not required.

So this is the minimum valid requirement for an image input when using the W3C validtor to validate an HTML5 page:

<input type="image" alt="Alt Text Here">


Related posts:


Comments