In html5 to set a checkbox as checked, should i simply use checked ( as a property) or checked=“checked” ( as an attribute)?

Currently in our plugin we were setting the checkboxes as checked by setting

<input type="checkbox" checked="checked" />

This was to preserve xhtml compatibility. I'm more used to setting checked as a property

<input type="checkbox" checked />

What is the correct way to proceed in html5?Should we still care about xhtml compatibility?


It is an attribute in either case. And it sets a value (the same value, true) on a DOM property of the element node in either case.

For most purposes, it does not matter which syntax you use. However, there are some points to note:

  • If you use HTML5 in XML serialization (“XHTML5”), you must use checked="checked".
  • In styling, the syntaxes are not quite equivalent when using attribute selectors (the shorter form does not match [checked=checked]), but this does not matter in practice: [checked] matches checked checkboxes in either case.
  • The clumsy syntax checked="checked" is a holdover from SGML and included for compatibility only, so it may make your code look old-fashioned (which rarely matters).

Need Your Help

MIPS Instruction in Data Directive

assembly mips directive mars-simulator

I'm trying to figure out what this program does, but I have a feeling MARS isn't handling the .data directive correctly.

Dynamically change css fontSize with jQuery or css

javascript jquery html css

I have a span that needs its font-size value changed when the window is resized. I do that with the jquery code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.