Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is <form> a block element?

Tags:

html

forms

The purpose of a <form> element, IMO, is semantic not presentational - the element is there to define an area with elements which can be sent to the server.

Why then, does the browser (and, I assume in the spec), specify display:block in the user agent stylesheet? Surely, if you want to have the form be a block, you can just wrap it in a div element?

Usually, I just put form { display: inline } into my css to override this. Still, I'm wondering if there was a good reason for making the <form> display as a block by default, or if it's just been kept that way for legacy reasons.

like image 399
Jords Avatar asked Sep 18 '12 04:09

Jords


People also ask

Is form a block element?

HTML 3.2 defines the <FORM> element as a block level element. The current behaviour of browsers regarding this element is certainly for backwards compatibility.

What does block element mean?

So what is a block-level element? A block-level element is an HTML element that begins a new line on a web page and extends the full width of the available horizontal space of its parent element. It creates large blocks of content like paragraphs or page divisions. In fact, most HTML elements are block-level elements.

Is aside a block element?

# aside. Defines a block of content that is related to the main content.

What is a form element?

The form element inserts a component designed to contain controls that users can interact with to send information back to the server. This element is commonly used to gather information from the visitors of a website, like preferences, comments, opinions and a lot more.


Video Answer


1 Answers

I assume this is because a <form> will very often contain other block level elements (div's for structure, or though I cringe at the thought, tables to help organize form fields, etc.). And having an inline element that contains block elements, while entirely possible, is semantically questionable.

I completely agree with your point about <form> not being presentational, but at the same time it makes sense to me that it would be a block element, given how the tag is generally used.

like image 60
aroth Avatar answered Oct 12 '22 23:10

aroth