라벨과 레전드를 제목으로 만들기
폼(form)을 설계할 때는 하나의 페이지에 하나의 것만 담도록 폼을 여러 페이지로 나누는 것부터 시작해야 해요. 예를 들면:
- 사용자에게 알려주는 정보 하나
- 사용자가 내려야 할 결정 하나
- 사용자가 답해야 할 질문 하나
이렇게 하면 사용자가 무엇을 요구받고 있는지 집중하고 이해하는 데 도움이 돼요.
출처: 문서
본문
폼(form)을 설계할 때마다 폼을 여러 페이지로 나누고, 각 페이지에는 한 가지만 담는 것부터 시작해야 해요. 예를 들면:
- 사용자에게 알려주는 정보 하나
- 사용자가 내려야 할 결정 하나
- 사용자가 답해야 할 질문 하나
이렇게 하면 사용자가 무엇을 요구받고 있는지 집중하고 이해하는 데 도움이 돼요.
페이지에서 질문을 하나만 하고 있다면, 그 질문을 페이지의 제목으로 만들 수 있어요. 그러면 페이지 제목이 입력 요소의 <label> 또는 <legend>와 대부분 같아질 거예요.
예를 들어 사용자에게 우편번호만 묻는 페이지에서는 '우편번호가 무엇인가요'라는 질문이 페이지 제목이자 텍스트 입력의 가장 논리적인 <label>이 돼요.
반복을 피하기 위해 시각적으로 숨겨진 <label> 또는 <legend>를 쓰는 방법도 있어요.
하지만 이 방법은 시각적 중복만 없앨 뿐, 화면 낭독기(screen reader) 사용자에게는 도움이 되지 않아요. 그들은 여전히 페이지 제목과 시각적으로 숨겨진 <label> 또는 <legend>를 둘 다 듣게 될 거예요.
이를 막으려면 <label> 또는 <legend>의 내용을 페이지 제목으로 설정하세요 (페이지에서 질문을 두 개 이상 묻는 경우는 예외예요).
라벨을 페이지 제목으로 만들기
라벨의 내용을 페이지 제목으로 설정하려면 <label> 태그를 <h1> 태그 안에 넣어야 해요. HTML로 직접 하거나, Nunjucks 매크로를 사용하고 isPageHeading: true로 설정하면 돼요.
그런 다음 <label>이 제목처럼 보이도록 클래스를 적용해야 해요.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="example">
govuk-label--l
</label>
</h1>
<div id="example-hint" class="govuk-hint">
This example shows an <h1> around a <label> with the class of govuk-label--l
</div>
<input class="govuk-input" id="example" name="example" type="text" aria-describedby="example-hint">
</div>
{% from "govuk/components/input/macro.njk" import govukInput %}
{{ govukInput({
label: {
text: "govuk-label--l",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "This example shows an <h1> around a <label> with the class of govuk-label--l"
},
id: "example",
name: "example"
}) }}
레전드를 페이지 제목으로 만들기
레전드의 내용을 페이지 제목으로 설정하려면 <legend> 태그를 <fieldset> 태그 밖에 두어야 해요. 이 역시 HTML로 직접 하거나, Nunjucks 매크로를 사용하고 isPageHeading: true로 설정하면 돼요.
라벨과 마찬가지로 <legend>가 제목처럼 보이도록 클래스를 적용해야 해요.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="checkbox-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
govuk-fieldset__legend--l
</h1>
</legend>
<div id="checkbox-hint" class="govuk-hint">
This example shows an <h1> inside a <legend> with the class of govuk-fieldset__legend--l
</div>
<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox" name="checkbox" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox">
Checkbox 1
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox-2" name="checkbox" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox-2">
Checkbox 2
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox-3" name="checkbox" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox-3">
Checkbox 3
</label>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
name: "checkbox",
fieldset: {
legend: {
text: "govuk-fieldset__legend--l",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "This example shows an <h1> inside a <legend> with the class of govuk-fieldset__legend--l"
},
items: [
{
value: "checkbox",
text: "Checkbox 1"
},
{
value: "checkbox",
text: "Checkbox 2"
},
{
value: "checkbox",
text: "Checkbox 3"
}
]
}) }}
라벨과 레전드의 스타일링 옵션
페이지 제목으로 스타일링하는 대신, 라벨과 레전드에 다른 클래스를 적용해 기본보다 더 크고 굵게 만들 수도 있어요.
라벨 스타일링하기
<div class="govuk-form-group">
<label class="govuk-label govuk-label--m" for="example">
govuk-label--m
</label>
<div id="example-hint" class="govuk-hint">
This example shows a <label> with the class of govuk-label--m
</div>
<input class="govuk-input" id="example" name="example" type="text" aria-describedby="example-hint">
</div>
<div class="govuk-form-group">
<label class="govuk-label govuk-label--s" for="example-2">
govuk-label--s
</label>
<div id="example-2-hint" class="govuk-hint">
This example shows a <label> with the class of govuk-label--s
</div>
<input class="govuk-input" id="example-2" name="example2" type="text" aria-describedby="example-2-hint">
</div>
{% from "govuk/components/input/macro.njk" import govukInput %}
{{ govukInput({
label: {
text: "govuk-label--m",
classes: "govuk-label--m"
},
hint: {
text: "This example shows a <label> with the class of govuk-label--m"
},
id: "example",
name: "example"
}) }}
{{ govukInput({
label: {
text: "govuk-label--s",
classes: "govuk-label--s"
},
hint: {
text: "This example shows a <label> with the class of govuk-label--s"
},
id: "example-2",
name: "example2"
}) }}
레전드 스타일링하기
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="checkbox1-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
govuk-fieldset__legend--m
</legend>
<div id="checkbox1-hint" class="govuk-hint">
This example shows a <legend> with the class of govuk-fieldset__legend--m
</div>
<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox1" name="checkbox1" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox1">
Checkbox 1
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox1-2" name="checkbox1" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox1-2">
Checkbox 2
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox1-3" name="checkbox1" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox1-3">
Checkbox 3
</label>
</div>
</div>
</fieldset>
</div>
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="checkbox2-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s">
govuk-fieldset__legend--s
</legend>
<div id="checkbox2-hint" class="govuk-hint">
This example shows a <legend> with the class of govuk-fieldset__legend--s
</div>
<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox2" name="checkbox2" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox2">
Checkbox 1
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox2-2" name="checkbox2" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox2-2">
Checkbox 2
</label>
</div>
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="checkbox2-3" name="checkbox2" type="checkbox" value="checkbox">
<label class="govuk-label govuk-checkboxes__label" for="checkbox2-3">
Checkbox 3
</label>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{{ govukCheckboxes({
name: "checkbox1",
fieldset: {
legend: {
text: "govuk-fieldset__legend--m",
classes: "govuk-fieldset__legend--m"
}
},
hint: {
text: "This example shows a <legend> with the class of govuk-fieldset__legend--m"
},
items: [
{
value: "checkbox",
text: "Checkbox 1"
},
{
value: "checkbox",
text: "Checkbox 2"
},
{
value: "checkbox",
text: "Checkbox 3"
}
]
}) }}
{{ govukCheckboxes({
name: "checkbox2",
fieldset: {
legend: {
text: "govuk-fieldset__legend--s",
classes: "govuk-fieldset__legend--s"
}
},
hint: {
text: "This example shows a <legend> with the class of govuk-fieldset__legend--s"
},
items: [
{
value: "checkbox",
text: "Checkbox 1"
},
{
value: "checkbox",
text: "Checkbox 2"
},
{
value: "checkbox",
text: "Checkbox 3"
}
]
}) }}
더 알아보기 (Learn more)
GOV.UK Design System에 대해 궁금한 점이 있다면 팀에 문의하세요.