Testing

maxlength: Browser Support, Usage, Known Issues

maxlength caps input and textarea length in Chrome 4+, Edge 12+, Firefox 4+, Safari 5.1+, IE 10+, and iOS Safari 4+. Test it on real browsers.

Author

Prince Dewani

May 6, 2026

The HTML maxlength attribute caps how many UTF-16 code units a user can type into an input or textarea field. It works in Chrome 4+, Edge 12+, Firefox 4+, Safari 5.1+, Opera 15+, IE 10+, iOS Safari 4+, Samsung Internet 4+, and Android Browser 2.3+; IE 6 to 9 and Safari 3.2 to 4 have partial support.

This guide covers what maxlength is, the browsers that support it, how it works, why it fails, and known issues to test.

What is maxlength?

The maxlength attribute is a standard HTML form attribute defined by the WHATWG HTML living specification. It limits the length of text a user can enter into an input element (in text, search, tel, url, email, or password mode) or a textarea. The browser stops further typing once the limit is reached.

Which browsers does maxlength support?

maxlength is a Baseline Widely available feature with around 97 percent global support, but a handful of older engines and edge browsers ship only partial support that you still need to test for.

Loading browser compatibility data...

maxlength compatibility in Chrome

Chrome supports maxlength by default from Chrome 4 on for both desktop and Android. Every current Chrome release enforces the cap on input and textarea with no flag, and Chrome on Android matches the desktop behavior.

maxlength compatibility in Edge

Edge supports maxlength by default from Edge 12 on across Windows, macOS, and Linux. Both the legacy EdgeHTML build and the current Chromium-based Edge enforce the limit by default, with no behavioral difference from Chrome.

maxlength compatibility in Firefox

Firefox supports maxlength by default from Firefox 4 on for desktop and Android. Firefox 2 to 3.6 had partial support, where the attribute was honored on input but the textarea element ignored it. Modern Firefox treats both elements consistently.

maxlength compatibility in Safari

Safari supports maxlength by default from Safari 5.1 on macOS and Safari 4 on iOS. Safari 3.2 to 4 on macOS and Safari 8 to 8.4 on iOS had partial support, where the attribute was read but not always enforced on the textarea element. Always check paste behavior on Safari before shipping a length cap.

maxlength compatibility in Opera

Opera supports maxlength by default from Opera 15 on, the first Chromium-based release. Opera 9.5 to 12.1 had partial support under the older Presto engine, and Opera Mini still ships only partial support because it serializes pages through a proxy that strips client-side validation.

maxlength compatibility in Samsung Internet

Samsung Internet supports maxlength by default from Samsung Internet 4 on every Android version it ships on. The behavior tracks Chrome on Android closely because both engines run on Blink, but Samsung keyboards on Galaxy devices have surfaced paste regressions that warrant a separate test pass.

maxlength compatibility in Android Browser

The legacy Android Browser, the WebView that shipped before Chrome on Android took over, supports maxlength from Android 2.3 on. This only matters on legacy hardware and pre-installed WebViews; modern Android devices route web content through Chromium WebView, which mirrors Chrome behavior.

maxlength compatibility in Internet Explorer

Internet Explorer supports maxlength by default from IE 10 on. IE 6 to 9 had partial support, where the attribute capped keystroke input but did not enforce paste events or programmatic value changes. Microsoft has retired Internet Explorer, so this only matters for intranet apps still locked to legacy IE.

Note

Note: maxlength behaves differently across Safari, Android Chrome, and Samsung Internet on real devices. Test it on real browsers and OS with TestMu AI. Try TestMu AI free!

How does the maxlength attribute work?

maxlength tells the browser to stop accepting user keystrokes once the field value reaches the declared length, measured in UTF-16 code units. It runs as part of the HTML constraint validation API, and the browser exposes a tooLong flag on the field's ValidityState whenever the value somehow exceeds the cap.

  • Allowed values: A non-negative integer (0 or higher). Any other value is treated as no limit at all.
  • UTF-16 counting: An emoji built from a surrogate pair counts as two units, so the visible character count and the maxlength count can drift apart.
  • User input only: Constraint validation runs when the user types or pastes. Setting element.value from JavaScript bypasses the cap entirely.
  • Eligible elements: Only input in text, search, tel, url, email, or password mode, plus the textarea element. Other input types ignore the attribute.

Use feature detection to confirm the platform supports the maxLength DOM property and read ValidityState.tooLong to react when a user crosses the bound.

// Feature-detect maxlength on the platform
const probe = document.createElement('input');
const supportsMaxLength = 'maxLength' in probe;
console.log(supportsMaxLength ? 'maxlength supported' : 'maxlength missing');

// Watch a real field and react when the user hits the cap
const username = document.querySelector('#username');
username.addEventListener('input', () => {
    if (username.validity.tooLong) {
        console.log('User typed past the maxlength bound');
    }
});

Why is maxlength not working?

The attribute itself is supported across every modern engine, so when maxlength looks broken the cause is almost always one of four mistakes in the markup or framework wiring above it.

  • type="number" on the input: Numeric inputs ignore maxlength outright. Use the min and max attributes for range bounds, or switch to type="text" with a pattern attribute to bound character count.
  • Lowercase maxlength in React: JSX requires camelCase, so write maxLength={50}. Lowercase maxlength is treated as an unknown attribute and dropped silently from the rendered DOM.
  • Programmatic value assignment: Setting field.value from a script bypasses constraint validation. Trim the value yourself before assigning, or dispatch an InputEvent if you need the browser to enforce the cap.
  • Custom contenteditable widgets: Rich text editors built on contenteditable do not honor maxlength because the attribute is only valid on input and textarea. Track length manually with an input event listener.

In my experience, the React camelCase trap is the single most common production bug we see for this attribute, and it ships silently because lint rules rarely flag a missing maxLength.

...

What are the known issues with maxlength?

maxlength has a wide support footprint, but the edge cases break in browser-specific ways that only show up on real devices.

  • Surrogate pair drift: Emoji and astral-plane characters count as two UTF-16 units. A field labeled "up to 10 characters" cuts off after five flag emoji, which surprises users.
  • Android paste regressions: Some Samsung Internet and stock Android Browser builds let users paste past the cap, then truncate on next keystroke. Always test paste flows on a real Android device.
  • iOS autocomplete bypass: iOS Safari occasionally accepts an autofill or QuickType suggestion that exceeds the maxlength, which leaves validity.tooLong true on submit.
  • Opera Mini partial enforcement: Opera Mini renders pages through a server-side proxy, so maxlength is only enforced after the form posts back, never live as the user types.
  • Form submission semantics: A maxlength violation does not block form submission unless you also call form.checkValidity. The browser leaves the responsibility to the page.
...

Citations

All maxlength version numbers, behavior notes, and platform claims in this guide come from these primary sources:

Author

Prince Dewani is a Community Contributor at TestMu AI, where he manages content strategies around software testing, QA, and test automation. He is certified in Selenium, Cypress, Playwright, Appium, Automation Testing, and KaneAI. Prince has also presented academic research at the international conference PBCON-01. He further specializes in on-page SEO, bridging marketing with core testing technologies. On LinkedIn, he is followed by 4,300+ QA engineers, developers, DevOps experts, tech leaders, and AI-focused practitioners in the global testing community.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

Frequently asked questions

Did you find this page helpful?

More Related Hubs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests