Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<section> inside a <form>

Tags:

html

Is it a valid thing to put a <section> inside a <form>?

Now, I know it works, so I'm not asking whether it works or not. I also know that they both are (both section and form) "box-model" elements and "may be inlined inside each other" -- according to the W3 definitions. And yet, I'm wondering if it's a legit thing to do?

Example for clarity:

<form action="foo.bar">
 <section>
  <input type="foo" />
 </section>
</form>
like image 487
Aviad Avatar asked Nov 24 '14 11:11

Aviad


People also ask

Can we use div inside form?

It is totally fine . The form will submit only its input type controls ( *also Textarea , Select , etc...). You have nothing to worry about a div within a form .

Can you put a section inside a section?

Sectioning elements can be nested inside one another as many times as is needed based on the content. The header and footer in a sectioning element can also contain sectioning elements.

Does section go inside main?

You can use <section> inside the <main> tag. According to W3Schools, this is not accurate. "The content inside the <main> element should be unique to the document.

Can a form be inside another form?

"Every form must be enclosed within a FORM element. There can be several forms in a single document, but the FORM element can't be nested."


1 Answers

In HTML5 you should use the tags that are most semantically appropriate for a given task.

And indeed there is a section tag for forms – it is called fieldset.

So instead of using a section tag inside your form, you might use a fieldset:

<form action="foo.bar">
    <fieldset>
        <legend>The fiedlset heading</legend>
        <input type="foo" />
    </fieldset>
</form>

Please also refer to the „html5 Doctor Element Flowchart“ (PNG, also as PDF).

like image 123
feeela Avatar answered Oct 17 '22 19:10

feeela