Reputation: 11140
Assuming HTML5, what is the correct way to indicate a checkbox, radiobutton, or select option is checked or selected?
Is it like this, which appears to be commonly used but seems strangely redundant to me:
<input type='checkbox' checked='checked'> I'm checked
<input type='radio' checked='checked'> I'm also checked
<select>
<option>First</option>
<option selected='selected'>I'm selected</option>
</select>
Or like this, which seem to make more sense and also appears to work:
<input type='checkbox' checked> I'm checked
<input type='radio' checked> I'm also checked
<select>
<option>First</option>
<option selected>I'm selected</option>
</select>
Are there any compatibility issues with the latter?
Upvotes: 0
Views: 98
Reputation: 31
Both ways seem to pass the W3 HTML5 validator, so they should both be correct. I prefer the second approach as it uses less code and is easier to me, but that's completely personal.
Upvotes: 1
Reputation: 91
You can use checked
or selected
on their own.
https://developer.mozilla.org/en/docs/Web/HTML/Element/select#Examples
Upvotes: 1