Why does input not require a closing tag?

These are void elements! This means they aren’t designed to contain text or other elements resulting in them not needing or being able to have a closing tag like

A void element is any element that can not, by definition, have any content in between the start and end tags, but the only type of data that void elements are allowed to have are attributes.

However, they can have a <label> associated with them:

Biscuit Label

I have discovered that using or not using closing tab with input or img doesn’t make any difference. So I don’t bother about this and just use both opening and closing tags always.

HTML is very tolerant of any sort of developer notions. However, validators will tell us when something is not needed, meaning we should adopt the accepted norms of well-formedness. Adding superfluous tags is tantamount to a refusal to conform. The old rule of human nature still applies… Assimilate or perish. If you wish to be taken seriously by any future employer, best to not embarrass yourself by exhibiting a resistance to standards.

5 Likes

That’s not a very good thinking to have as a coder is it?

To add a little something here, you may denote that the input element is a self closing tag by providing a / before the closing bracket. It’s not required though :slight_smile:

Example:

<input type="text" name="username" placeholder="What's your name?" />

Is this anything of added value? Did we not already know this?

1 Like

Thank you for taken out your time to explain this. It is very helpful

Sir, Can we get the list of all void elements in HTML?
That will be helpful.

I would start here and carefully peruse the text. Use F3 to search for void and notice all the yellow highlighting?

@mtf Thank you so much sir.

1 Like

why we are using “text” as a value of type attribute?
is it because or means we are expecting a string of text and not a numerical value? please answer

1 Like

You’re like Coding Jesus :joy:. Idk if you were a teacher, but your clear and concise explanations + the structure of your writing really give off that vibe. Thanks for all of your answers!

2 Likes

the input element does not require a closing tag because it is used to create various types of form controls, such as text fields, checkboxes, radio buttons, and buttons. It is self-contained element and doesn’t have any content between an opening and closing tag like other elements do.

1 Like

Are we learning latest computer languages in Codecademy?

1 Like

Yes! Codeacademy is making sure of that.

1 Like