Required attributes for HTML5 image inputRequired attributes for HTML5 image input

Posted March 20th, 2010 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:

Share or Bookmark

Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.

Subscribe or Follow

Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

Comments

blog comments powered by Disqus