How to limit input text length using CSS3?


With HTML, you can easily limit input length. However, with CSS3, it will not be possible, since CSS can’t be used to limit the number of input characters. This will cause a functional restriction.

CSS deals with presentation i.e. how your web page will look. This is done with HTML attribute malength, since it’s for behavior.

Let’s see how to do it in HTML −

Example

You can try to run the following code to limit input text length

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <title>HTML maxlength attribute</title>
   </head>
   <body>
      <form action="">
         Student Name<br><input type="text" name="name" maxlength="20"><br><br>
         <input type="submit" value="Submit">
      </form>
   </body>
</html>

Vikyath Ram
Vikyath Ram

A born rival

Updated on: 25-Feb-2020

660 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements