treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] HTML5 Proper Structure - Form Tag

  • Hello All!

    With HTML5, we are encouraged to use <article>, <section>, <header>, etc tags in place of the <div> tags when appropriate. Would it be semantically correct to use the <form> tag in the same manner for a form in a webpage and style it as I would one of the above elements?

    Example:

      <form class="form-container">
          <!-- Form Stuffs -->
      </form>
    

    VS

      <div class="form-container">
          <form>
              <!-- Form Stuffs -->
          </form>
      </div>
    

    To me, it seems logical to use it the first method above. After all, that section of content is a form and adding a <section> or <div> container seems like code bloat. Thanks in advance.

  • 'Form' itself does nothing so, in essence it's exactly the same as a div or section.

    Here's what HTML5 Doctor says:

    The form element represents a collection of form-associated elements, some of which can represent editable values that can be submitted to a server for processing.

    So in answer to your question...yes, it would be semantically correct to use the 'form' element as a wrapper without needing to wrap it in another element.

  • Thank you for the quick and well referenced response, Paulie_D. Much appreciated.