tags:

views:

307

answers:

5

Can I replace the maxlength attribute with something in CSS?

<input type='text' id="phone_extension" maxlength="4" />
+2  A: 

Not with CSS, no.

JMP
+9  A: 

No.

maxlength is for behavior.

CSS is for styling.

That is why.

Developer Art
+1 for giving reason
Residuum
Also, CSS can be applied globaly to any tag, so it wouldn't make sense to have a maxlength property applied to a div or img etc.
Dan Diplo
+9  A: 

No. This needs to be done in the HTML. You could set the value with Javascript if you need to though.

edeverett
+4  A: 

I don't think you can, and CSS is supposed to describe how the page looks not what it does, so even if you could, it's not really how you should be using it.

Perhaps you should think about using JQuery to apply common functionality to your form components?

Charlie
+1  A: 

Not with CSS, but you can emulate and extend / customize the desired behavior with JavaScript.

code_burgar