HTML maxlength 속성은 HTML 문서의 입력 HTML 요소에 허용되는 최대 문자 수를 정의합니다.
구문
다음은 구문입니다 -
<input maxlength=”text”>
HTML maxlength 속성의 예를 살펴보겠습니다 -
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
text-align: center;
}
input {
width: 300px;
background: transparent;
border: 2px solid #fff;
outline: none;
display: block;
margin: 1rem auto;
border-radius: 20px;
padding: 8px 10px;
}
::placeholder {
color: #000;
}
.btn {
background: #db133a;
color: #fff;
border: none;
width: 320px;
}
</style>
<body>
<h1>HTML maxlength Attribute Demo</h1>
<form action="">
<input type="text" placeholder='Enter your first name(only 8 characters)' maxlength="8">
<input type="submit" value="SUBMIT" class="btn">
</form>
</body>
</html> 출력

이제 입력 필드에 8자 이상을 입력하여 maxlength 속성이 작동하는 방식을 관찰하십시오 -
