view raw
bornfree bornfree - 6 months ago 44
HTML Question

Why does the output differs in the given html code?

When i open the html file with the code snippet, mentioned below, in my browser i see a checkbox and a submit button.

<form >
<input type = "checkbox" name = "q">
<input type = "submit">

However, when I move the first line along with the form(as shown in the code snippet below) and then reload the file in my browser, I don't see the checkbox. I see only the submit button.
I infer that mentioning the first line along with form keyword means something different. Can someone explain what is the difference ?

<form input type = "checkbox" name = "q">
<input type = "submit">

PS: I am new to html and web development. This may be a noob question.


As per definition, the <form> tag is used to create an HTML form for user input. This form contains other elements such as <input>, <button>, <textarea>, etc. These elements cannot be clubbed into the form tag.

When you write :

<form input type = "checkbox" name = "q">

it creates an element form with attributes type="checkbox", name="q" and input="" and therefore it doesn't create the checkbox you wanted.

The correct format is :

    <!-- form content -->