Proper nesting of form tags in HTML

234 views Asked by At

I am replicating a page, and wanted to know if I need to indent the form tag, if it is nested inside of a div tag. e.g.

      <div class="signup-form">
        <form method="post">
          <input type="text" value="First Name">
          <input type="text" value="Last Name">
        </form>

Or do I write it without the indentation. e.g.

      <div class="signup-form">
      <form method="post">
        <input type="text" value="First Name">
        <input type="text" value="Last Name">
      </form>

Thank you in advance.

2

There are 2 answers

1
Donal On BEST ANSWER

Indentation in HTML does not matter, it is purely for readability.

For readability, in your example, I would indent.

I would indent because the form tag is contained within the div tag.

<div class="signup-form">
  <form method="post">
    <input type="text" value="First Name">
    <input type="text" value="Last Name">
  </form>
</div>

0
ѺȐeallү On

Indentation doesn't affect the way your markup is interpreted. You can follow a standard for readability or your own stylistic preference.

You could also let the IDE format the code for you...

Visual Studio: ctrl + k, ctrl + d

Sublime Text 3: Just select all lines ctrl + a and then from the menu select Edit → Line → Reindent