# What is the reason that the authenticity\_token hidden field gets wrapped in a DIV?

**URL:** <https://www.ruby-forum.com/t/what-is-the-reason-that-the-authenticity-token-hidden-field-gets-wrapped-in-a-div/166100>\
**Category:** Rails\
**Created:** [April 21, 2009, 9:26pm UTC](https://www.ruby-forum.com/t/what-is-the-reason-that-the-authenticity-token-hidden-field-gets-wrapped-in-a-div/166100 "2009-04-21T21:26:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [April 21, 2009, 9:26pm UTC](https://www.ruby-forum.com/t/what-is-the-reason-that-the-authenticity-token-hidden-field-gets-wrapped-in-a-div/166100/1 "2009-04-21T21:26:59Z")

</div>

Hi all -

This has never been an issue for me until today. However I have a  
form and Rails is inserting it’s hidden authenticity\_token field. It  
wraps it in a div with a style. And doing that messes things up for  
me CSS wise.

Which got me to thinking about why it’s wrapped at all? Hidden fields  
don’t take up any room. Why wrap it in a div which can have some side  
affects? And if we’re going to wrap it, why not at least give it a  
class so we can target it and set display:none which fixes the problem.

Can anyone shed some light on why this is the case? If there’s no  
good reason it seems like the wrapped div should go away shouldn’t it?

-philip

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [April 21, 2009, 10:22pm UTC](https://www.ruby-forum.com/t/what-is-the-reason-that-the-authenticity-token-hidden-field-gets-wrapped-in-a-div/166100/2 "2009-04-21T22:22:20Z")

</div>

Following up. Looks like I’m not the only one who doesn’t like this…

[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2044](https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2044)

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [April 22, 2009, 12:31pm UTC](https://www.ruby-forum.com/t/what-is-the-reason-that-the-authenticity-token-hidden-field-gets-wrapped-in-a-div/166100/3 "2009-04-22T12:31:30Z")

</div>

> Can anyone shed some light on why this is the case? Â If there’s no  
> good reason it seems like the wrapped div should go away shouldn’t it?

> Â 
> 
> Â Â

According to (X)HTML specification you cannot have inline elements  
inside form, so inputs  
must be wrapped in something: fieldset, p or div.

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [April 22, 2009, 5:58pm UTC](https://www.ruby-forum.com/t/what-is-the-reason-that-the-authenticity-token-hidden-field-gets-wrapped-in-a-div/166100/4 "2009-04-22T17:58:13Z")

</div>

> According to (X)HTML specification you cannot have inline elements  
> inside form, so inputs  
> must be wrapped in something: fieldset, p or div.

Ah, that would explain it then! Thanks. To anyone else who has  
issues with this and CSS, check out the below patch. It works great  
on 2.3.2. Basically I can override the style and set it to  
display:none or display:inline…

[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2044](https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2044)
