How to add a "Checked" attribute to an "Input" element>>>

Hi Err’body :slight_smile: :slight_smile:

I’m stuck.

I am required to add a “Checked” attribute to an “Input” element in order for the radio button to be selected by default.

Below is how my code looks.

<fieldset>
            <legend>Is your cat an indoor or outdoor cat?</legend>
            <label><input id="indoor" type="radio" name="indoor-outdoor" value="indoor" checked="default">Indoor</label>
            <label><input id="outdoor" type="radio" name="indoor-outdoor" value="outdoor" checked="default">Outdoor</label>
          </fieldset>

Thank you in advance guys.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

The attribute checked is special and does not need a value as it means that the button is in a checked state.

Also, please post a link to the challenge.

Oh, please excuse me. Now I know. Thank you so much :slight_smile:

Here’s the link:

Learn HTML by Building a Cat Photo App: Step 61 | freeCodeCamp.org

Also, I get what you mean about dropping the value as it’s not required. But how would I code it in. Because I tried and it still results in an error.

I did it this way:

`<label><input id="indoor" type="radio" name="indoor-outdoor" value="indoor" checked> Indoor</label>`

It won’t budge.

Read this instruction again

Make the first radio button and the first checkbox selected by default.

I will rewrite it to make it clearer for you.

Make [both] the first radio button
and the first checkbox
selected by default.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.