Last updated 31 October 2017. Created on 8 October 2011.
Edited by cferthorney, droweski, nicrodgers, jm.federico. Log in to edit this page.

D7: 7.x-3.x

Maxlength creates a new Form Property: #maxlength_js which in conjunction with #maxlength will enforce, via JavaScript, the maxlength of a textfield, a textarea, or a text_format and will show the number of characters left.

UI Usage

When editing the a text field widget's settings, you can set the character limit to be controlled with Maxlength. Widgets currently accepted are:

  • Text area (multiple rows)
  • Text area with a summary
  • Text field


Maxlength creates a new 'bypass max length' permission. This is assigned to the Administrator role by default. Therefore, when you first install Maxlength, administrators will not see the counter.


Module is compatible with tinyMCE and CKEditor using the wysiwyg module

Code (api?) Usage

Whether when creating a form or when altering one, put both #maxlength and #maxlength_js properties on the elements you want to control.


Description: The maximum amount of characters to accept as input.

Values: A positive number.


Used by: textfield, textarea, text_format

Description: Indicates whether or not the field should have a reverse character counter.

Values: TRUE or FALSE

FAPI Example

  $form['description'] = array(
    '#required' => '1',
    '#description' => t('Max. 500 Characters'),
    '#type' => 'textarea',
    '#maxlength' => 500,
    '#maxlength_js' => TRUE,
    '#attributes' =>array(
      'maxlength_js_label' => '@remaining characters left.',
    '#title' => t('Detailed Description (required)'),

Looking for support? Visit the forums, or join #drupal-support in IRC.


myselfhimself’s picture

I had been using maxlength_js on my site so far. Disabling it and installing maxlength in place seems to make the characters limit continue working. Is maxlength truly a drop-in replacement for maxlength_js ? Are they any upgrade path instructions from maxlength_js to maxlength for making things properly and avoid a break in further maxlength updates or so?
Thanks in advance!

HAL 9000’s picture

Do not forget: superuser has all rights, if you would like to test it, use a user who has not "Bypass maxlength setting" right.

mohaly’s picture

What about using this module in Drupal 8, I can't apply it with body field.