# Why does this add \<div style="margin:0;padding:0"\>?

**URL:** <https://www.ruby-forum.com/t/why-does-this-add-div-style-margin-0-padding-0/92674>\
**Category:** Rails\
**Created:** [April 22, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/why-does-this-add-div-style-margin-0-padding-0/92674 "2007-04-22T23:12:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 22, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/why-does-this-add-div-style-margin-0-padding-0/92674/1 "2007-04-22T23:12:21Z")

</div>

Hi,

I have the following form\_for tag that seems to be outputing any suggestions on how this can be stopped?

\<% form\_for :user, :url =\> user\_path(@user), :html =\> {:method =\> :put}  
do |f| %\>

cheers  
jon

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 23, 2007, 11:47am UTC](https://www.ruby-forum.com/t/why-does-this-add-div-style-margin-0-padding-0/92674/2 "2007-04-23T11:47:54Z")

</div>

Perhaps it adds the div due to compatibility with XHTML? I’m new here,  
and quite new to Ruby on Rails too, but it seems fairly reasonable that  
that’s what RoR is doing.

One must put a blocking object inside a form for it to be valid XHTML.

Valid:

Invalid:

I have no clue how to remove the div-element though, sorry.

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 23, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/why-does-this-add-div-style-margin-0-padding-0/92674/3 "2007-04-23T12:24:00Z")

</div>

torh wrote:

> Perhaps it adds the div due to compatibility with XHTML? I’m new here,  
> and quite new to Ruby on Rails too, but it seems fairly reasonable that  
> that’s what RoR is doing.
> 
> One must put a blocking object inside a form for it to be valid XHTML.
> 
> Valid:
> 
> Invalid:
> 
> I have no clue how to remove the div-element though, sorry.

Yes, it is one of my most hated Rails behaviours. It might be correct to  
wrap input fields inside a block element, but consider this:

Test

which is correct xhtml, too. But Rails adds a second (unnecessary) div  
around the input. It even hinders me in setting a custom class for this  
div. I think that some of the tag logic needs to be reworked.
