여러 줄 입력을 위한 textarea
textarea 요소로 여러 줄 텍스트 수집하기
여러 줄 입력을 위한 textarea은(는) CoddyKit의 무료 HTML Academy 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 HTML Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. HTML Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
텍스트 영역 요소
<textarea> 요소는 여러 줄의 텍스트 입력을 받습니다:
<label for="message">Message</label>
<textarea
id="message"
name="message"
rows="5"
cols="40"
placeholder="Enter your message here..."
></textarea>
<!-- textarea is NOT a void element -- it has a closing tag -->
<!-- Default content goes between the tags, not in a value attribute -->행 및 열 속성
rows와 cols는 처음 표시되는 크기를 설정합니다:
<!-- rows: height in lines (default: 2) -->
<!-- cols: width in characters (default: 20) -->
<textarea rows="6" cols="50">...</textarea>
<!-- Better: use CSS for sizing -->
<textarea style="width: 100%; height: 150px; resize: vertical;">기본 콘텐츠 설정
기본 텍스트는 여는 태그와 닫는 태그 사이에 작성합니다:
<textarea name="bio">
Hello! I am a developer who loves HTML.
</textarea>
<!-- Note: whitespace inside textarea IS rendered -->
<!-- The newline after the opening tag will appear in the textarea -->
<!-- Avoid whitespace between tags if you don't want it -->CSS로 크기 조절
CSS의 resize 속성으로 사용자가 크기를 조절하는 방식을 제어하십시오:
textarea {
resize: vertical; /* allow only vertical resize */
/* resize: horizontal -- only horizontal */
/* resize: both -- both directions (default) */
/* resize: none -- prevent resizing */
width: 100%;
min-height: 120px;
max-height: 400px;
padding: 0.5rem;
box-sizing: border-box;
}자동 확장 텍스트 영역
JavaScript로 사용자가 입력할 때 텍스트 영역이 확장되도록 만드십시오:
<textarea id="auto-grow" rows="3" style="overflow: hidden;"></textarea>
<script>
const ta = document.getElementById('auto-grow');
ta.addEventListener('input', () => {
ta.style.height = 'auto';
ta.style.height = ta.scrollHeight + 'px';
});
</script>최대 길이 및 최소 길이
텍스트 영역의 텍스트 길이를 제한하십시오:
<label for="bio">Bio (max 500 characters)</label>
<textarea
id="bio"
name="bio"
maxlength="500"
minlength="10"
rows="4"
></textarea>
<!-- Live character count: -->
<small id="char-count">0/500</small>
<script>
document.getElementById('bio').addEventListener('input', function() {
document.getElementById('char-count').textContent =
this.value.length + '/500';
});
</script>spellcheck 속성
spellcheck 속성은 맞춤법 검사를 제어합니다:
<!-- Enable (default for textarea) -->
<textarea spellcheck="true">...</textarea>
<!-- Disable (for code editors, technical input) -->
<textarea spellcheck="false">...</textarea>wrap 속성
wrap 속성은 줄바꿈이 제출되는 방식을 제어합니다:
<!-- wrap="soft" (default): text wraps visually but newlines not added -->
<textarea wrap="soft">...</textarea>
<!-- wrap="hard": newlines inserted at wrap points when submitted -->
<!-- Requires cols to be set -->
<textarea wrap="hard" cols="40">...</textarea>읽기 전용 및 비활성화
텍스트 영역을 편집할 수 없게 만드십시오:
<!-- readonly: visible, selectable, submitted -->
<textarea readonly>This is read-only text.</textarea>
<!-- disabled: cannot interact, not submitted -->
<textarea disabled>Disabled textarea.</textarea>텍스트 영역 접근성
텍스트 영역의 접근성 참고 사항:
- 항상
for/id를 사용하여<label>을 연결하십시오 - 도움말 텍스트나 글자 수 카운터를 연결하려면
aria-describedby를 사용하십시오 - 라이브 영역을 사용하여 글자 수 제한 변경 사항을 화면 판독기에 알리십시오
<label for="comment">Comment</label>
<textarea id="comment" aria-describedby="comment-hint"></textarea>
<p id="comment-hint">Maximum 200 characters.</p>텍스트 영역 스타일 지정
일반적인 텍스트 영역 스타일 지정:
textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 0.375rem;
font-family: inherit; /* match surrounding font */
font-size: 1rem;
line-height: 1.5;
resize: vertical;
min-height: 100px;
box-sizing: border-box;
transition: border-color 0.2s;
}
textarea:focus {
outline: none;
border-color: #0070f3;
box-shadow: 0 0 0 3px rgba(0,112,243,0.2);
}빠른 확인
텍스트 영역에 미리 입력된 텍스트를 설정하려면 어떻게 해야 하나요?
복습: 텍스트 영역
텍스트 영역 핵심 사항:
- 닫는 태그를 사용하는 여러 줄 텍스트 입력
- 기본 콘텐츠는
value속성이 아니라 여는 태그와 닫는 태그 사이에 작성합니다 rows와cols는 처음 크기를 설정하며, CSS를 우선 사용하십시오maxlength와minlength는 길이를 제어합니다- CSS에서
resize: vertical을 사용하면 크기 조절 방향을 제어할 수 있습니다 - 자동 확장: 입력 이벤트에서
height: scrollHeight를 설정합니다
자주 묻는 질문
“여러 줄 입력을 위한 textarea” 강의는 무료인가요?
네 — “여러 줄 입력을 위한 textarea” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 HTML Academy 강의 전체를 잠금 해제할 수 있습니다. HTML Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“여러 줄 입력을 위한 textarea”에서 뭘 배우나요?
textarea 요소로 여러 줄 텍스트 수집하기 브라우저에서 직접 실행하는 실습 코드로 HTML Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
HTML Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 HTML Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“여러 줄 입력을 위한 textarea” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 HTML Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 HTML Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- select와 option 드롭다운 메뉴
- 여러 줄 입력을 위한 textarea
- 체크박스 및 라디오 버튼 그룹
- 자동 완성을 위한 datalist