Is there more than 1 way to write code in HTML for the same task?

for example: if i want to create a checkbox for choosing 2 out of say 3 types of fruits-so can this be done by writing the code in different ways as written below?

<label>CHOOSE: Mango<input type="checkbox" name="fruit"></label>
<label> Apple<input type="checkbox" name="fruit"></label>
<label>Banana<input type="checkbox" name="fruit"></label>

OR

CHOOSE: Mango<input type="checkbox" name="fruit">
                         Apple<input type="checkbox" name="fruit">
                        Banana<input type="checkbox" name="fruit">

i got results on my browser by doing both of these. But is this the correct way? I appreciate your reply.

wow i just typed in 6 lines of code for explaining what i am doing and when i submit, the code typed in vanished. how am i supposed to ask for help? anyways, i am asking is it important to nest the element inside the or can it be done without using the label element?

Hello.
Select your code and press CTRL+Shift+C
Or you can select the code and click on an icon with this symbol </>

1 Like

hi!thank you very much

You can read this question about nested elements inside label tag.

<label>CHOOSE: Mango<input type="checkbox" name="fruit"></label>
<label> Apple<input type="checkbox" name="fruit"></label>
<label>Banana<input type="checkbox" name="fruit"></label>

This looks better and will oblige proper html practices. But you can improve it by adding the For attribute.

And this here is not a good way to write html because your browser has predefined browser styles which makes it to display whatever text you type in your editor.

CHOOSE: Mango<input type="checkbox" name="fruit">
                         Apple<input type="checkbox" name="fruit">
                        Banana<input type="checkbox" name="fruit">

When you write html using tags, you override the browser styles.

Hope this helps.

yes thank you so much!