Add classes to programmatically added fields I have programmatically created a few content types and fields for said content types in a module I'm building, but I need to add classes to said fields. 

So if I have a text field called "background_color", I would like to add a class to it called "color-picker".

Im added the instance of the field to my bundle like:

...
    'background_color' =&gt; array(
        'field_name' =&gt; $fields['field_background_color']['field_name'],
        'label' =&gt; 'The stroke color',
        'bundle' =&gt; 'nji_map',
        'entity_type' =&gt; 'node',
        'attributes' =&gt;array('class'=&gt;array('minicolors')),
        'widget'      =&gt; array(
            'type'    =&gt; 'text_textfield',
        ),
        'display' =&gt; array(
            'default' =&gt; array(
            'label' =&gt; 'above',
            'type' =&gt; 'text_textfield',
            ),
        ),
        'description' =&gt; 'The background color is the color between.',

    )....


Edit - Here is more of my code (node the full code snippet because there are too many fields)..

        $fields = array(
        'field_map_background_color' =&gt; array(
            'field_name' =&gt; 'field_map_background_color',
            'type' =&gt; 'text'
        ),...

$instances =  array(
    'background_color' =&gt; array(
        'field_name' =&gt; $fields['field_map_background_color']['field_name'],
        'label' =&gt; 'The background color',
        'bundle' =&gt; 'nji_map',
        'entity_type' =&gt; 'node',
        'attributes' =&gt;array('class'=&gt;array('minicolors')),
        'settings' =&gt; array(
            'prefix' =&gt; '&lt;div class = "minicolors"&gt;',
            'suffix' =&gt; '&lt;/div&gt;',
        ),
        'widget'      =&gt; array(
            'type'    =&gt; 'text_textfield',
        ),
        'display' =&gt; array(
            'default' =&gt; array(
            'label' =&gt; 'above',
            'type' =&gt; 'text_textfield',
            ),
        ),
        'description' =&gt; 'The background color is the color between.',

    ), ....

  foreach ($fields as $field) {
    field_create_field($field);
  }

  foreach ($instances as $instance) {
    field_create_instance($instance);
  }
Do something like this to wrap this field in a DIV class --

...
    'background_color' =&gt; array(
        'field_name' =&gt; $fields['field_background_color']['field_name'],
        'label' =&gt; 'The stroke color',
        'bundle' =&gt; 'nji_map',
        'entity_type' =&gt; 'node',
        'attributes' =&gt;array('class'=&gt;array('minicolors')),
        'widget'      =&gt; array(
            'type'    =&gt; 'text_textfield',
        ),
        'settings' =&gt; array(
          'prefix' =&gt; '&lt;div class = "my_field_div_class"&gt;',
          'suffix' =&gt; '&lt;/div&gt;',
        ),
        'display' =&gt; array(
            'default' =&gt; array(
            'label' =&gt; 'above',
            'type' =&gt; 'text_textfield',
            ),
        ),
        'description' =&gt; 'The background color is the color between.',

    )....


You would notice I have added settings along with other properties of the instance, where we can add prefix, sufix, min, max etc. I hope it works..