RocketNuts
RocketNuts

Reputation: 11140

HTML5 radiobuttons, checkbox and select option tags: checked='checked' and selected='selected', or just checked and selected

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

Answers (2)

Brendan B.
Brendan B.

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

Jim
Jim

Reputation: 91

You can use checked or selected on their own.

https://developer.mozilla.org/en/docs/Web/HTML/Element/select#Examples

Upvotes: 1

Related Questions