Place two text fields within a single  class I have assigned class names to both user name &amp; password text fields in user login block separately like this and it's working.

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id, $element) {
   if ( TRUE === in_array( $form_id, array( 'user_login', 'user_login_block') ) ) {
       $form['name']['#attributes']['class'] = array('mgnB10', 'fntXL', 'drkFg1');
       $form['pass']['#attributes']['class'] = array('fntXL', 'drkFg1');
   }
}


I want to include these fields inside a single '' and assign class name for design purpose, like this.

&lt;div class="class-name"&gt;
  username field
  password field
&lt;/div&gt;


I am using the following code but I didn't get the expected output.

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id, $element) {
   if ( TRUE === in_array( $form_id, array( 'user_login', 'user_login_block') ) ) {
       $form['user_login']['#attributes']['class'] = array('#prefix' =&gt; 'myclass');
       $form['name']['#attributes']['class'] = array('mgnB10', 'fntXL', 'drkFg1');
       $form['pass']['#attributes']['class'] = array('fntXL', 'drkFg1');
       $form['user_login'] = array('#suffix' =&gt; '&lt;/div&gt;');
   }
}
Hope this will help you,

In Drupal 7 you can achieve it by using the #prefix and #suffix properties in hook_form_alter().

   /**
    * Implements hook_form_alter().
    */
    function hook_form_alter(&amp;$form, &amp;$form_state, $form_id) {
      switch ($form_id) {
        case 'user_login':
        case 'user_login_block':
          $form['name']['#prefix'] = '&amp;#60;div class="username-password-wrapper"&amp;#62;';
          $form['pass']['#suffix'] = '&amp;#60;/div&amp;#62;';
          break;
      }
    }