# Adding a class to a generated input field

**URL:** <https://www.ruby-forum.com/t/adding-a-class-to-a-generated-input-field/120472>\
**Category:** Rails\
**Created:** [November 17, 2007, 9:20am UTC](https://www.ruby-forum.com/t/adding-a-class-to-a-generated-input-field/120472 "2007-11-17T09:20:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [November 17, 2007, 9:20am UTC](https://www.ruby-forum.com/t/adding-a-class-to-a-generated-input-field/120472/1 "2007-11-17T09:20:58Z")

</div>

Whne creating a field using for example:

\<%= text\_field\_tag :name, params[:name] %\>

You get:

I would like to add a class to that input so that it looks like this:

How do I add a class to a generated input?

(I want it as a CSS hook, and do not want to use the ID for that.  
Alternative is wrapping each input in a span with a class but thats a  
waste.)

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [November 17, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/adding-a-class-to-a-generated-input-field/120472/2 "2007-11-17T12:36:27Z")

</div>

On 17 Nov., 09:20, Steve O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do I add a class to a generated input?

That should do it:

text\_field\_tag :name, params[:name], :class =\> “field”

Stefan
