Size attributes just get in the way of responsive forms, and I realize most form fields can be overridden by CSS, but field types like input[type="file"] still do not behave well if a size attribute is set.

See this JSFiddle example.

Since field elements are classed out well, I'd much rather purely rely on CSS for field sizes. So, how can size attributes be removed from all fields?

3 Answers 3


For text fields the size attribute is forcibly added in theme_textfield(), so the only way would be to override that function in your theme and remove that bit of code:

function mytheme_textfield($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'text';

  // 'size' removed from this call
  element_set_attributes($element, array('id', 'name', 'value', 'maxlength'));

  // add the rest of the function...

Exactly the same thing goes for the file element (see theme_file()), and most likely for any other element type you need to do do this for.

  • this removes my input fields completely skitch.com/krisbulman/epnd5/admin-d7.kgbdev.local
    – krisbulman
    Commented Aug 16, 2012 at 18:31
  • Did you copy the rest of the function across? All the way down to return $output . $extra;?
    – Clive
    Commented Aug 16, 2012 at 18:31
  • my bad, I see you have to use the whole function now.. and it can be isolated on any field type. works like a charm.
    – krisbulman
    Commented Aug 16, 2012 at 18:37

You could do it with jQuery on the browser side like this, too:


input[type="file"] does not have size attribute, see http://www.w3schools.com/tags/att_input_size.asp

For D6, just add next lines to template.php (copied from includes/form.inc and removed size):

function phptemplate_file($element) {
    _form_set_class($element, array('form-file'));
    return theme('form_element', $element, '<input type="file" name="'. $element['#name'] 
        .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '')
        .' id="'. $element['#id'] ."\" />\n");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.