Labeling Controls

Back to Overview
00:00 --> 00:07
to think about that as well. And those basics, and we'll start from the top, I go linearly through

00:07 --> 00:13
this tutorial. If you rather want to read it, that's also totally fine. I probably go into

00:13 --> 00:20
a little bit more details. I might also, you know, give you a little bit more context

00:20 --> 00:27
in what I prefer, but in the grand scheme of things, like reading this tutorial is already a

00:27 --> 00:38
good start. So let's start at labeling controls. So what do I mean with that? So if we look at this

00:38 --> 00:43
example, so this is a typical form control. You have something where you can put in text,

00:43 --> 00:51
you can check the checkbox, and that's usually done with these input elements. So when you will

00:51 --> 00:59
do reviews for accessibility, you will see those inputs here, there is one there, one there. And

00:59 --> 01:08
these are basically, hey, put an input element, give user input or get user input on this page.

01:09 --> 01:20
And the label is this part at the front here of the text box and at the end of the checkbox. So

01:20 --> 01:26
So you already see that depending on the interactive element, the label can be somewhere else.

01:27 --> 01:32
And we get into like other more niche stuff in a second.

01:33 --> 01:39
But yeah, generally what you want to do is associating labels explicitly.

01:39 --> 01:49
And that means that if you have an input that has an ID first name, you can actually use a label for first name and assign that.

01:49 --> 02:04
What that does is that when a screen reader user clicks or taps into the input field, they get this label announced as the name of this input.

02:05 --> 02:13
And that's super important because otherwise you just have like text input and you don't know what you have to do.

02:13 --> 02:15
The same goes with the checkbox.

02:15 --> 02:22
if I press tab, now I'm on the checkbox and the checkbox on its own doesn't know what it is. But

02:22 --> 02:31
because we have the for and ID relationship here, it knows that subscribe to newsletter is the

02:31 --> 02:40
actual label for this element. And that's, you know, pretty straightforward. And that's always

02:40 --> 03:10
what you need to do. Like you need a visible label as well. So visible label, and then you have to connect it to the input element. Sometimes you want to hide label text and you can do that in some instances. Like in this example, you have a search button. And when you have the search button, this is a very commonly used

03:10 --> 03:18
user interface component, I want to say. If you have a search button here, you can,

03:19 --> 03:26
you know, you don't need to have search colon before the text input field. This together works

03:26 --> 03:34
as the label, as a visible label, and as the label also for the text element. Now,

03:35 --> 03:43
If we just put the text box on the left and the button on the right, then that means they are not connected.

03:43 --> 03:47
So this text box would not have a name.

03:47 --> 03:51
It would just say like text input and that's it.

03:52 --> 03:53
And that would be bad.

03:53 --> 03:57
So there are a couple of ways to do that.

03:57 --> 04:01
So you can use a label element and hide it using visually hidden.

04:02 --> 04:03
That's fine.

04:04 --> 04:09
I can use ARIA label and we're going to talk about ARIA label next week.

04:10 --> 04:19
But ARIA is basically a way to more or less directly communicate with screen readers.

04:19 --> 04:31
And in this case you have the input and you label it, you put a name on it that goes into the string at the bottom, at the back here.

04:31 --> 04:34
And then this is the same thing.

04:34 --> 04:40
I will not go into the ARIA labeled by example, because we can talk about a lot of ARIA next week.

04:40 --> 04:42
It will be like a really big, chunky topic.

04:43 --> 04:54
So I don't want to like do too much talking about that too much right now, because this is like, you know, need to know the basics.

04:55 --> 04:59
Here, you can also use the title.

05:00 --> 05:04
The title is the thing that shows up when you hover over something.

05:05 --> 05:08
You can have the title, but this is only fallback.

05:08 --> 05:10
I would not use the title.

05:10 --> 05:13
So ignore this part.

05:13 --> 05:20
Yeah, and this is the visually hidden class that puts away the label.

05:20 --> 05:28
But make sure that the label stays inside of the, like, you know, can be read by screen readers and whatnot.

05:28 --> 05:43
You can also associate labels implicitly and that's good for some situations where you don't have access to the code.

05:43 --> 05:48
So you have an input somewhere but you need to label it but you can't put an ID on it.

05:49 --> 05:53
This rarely happens these days, but it's still useful.

05:54 --> 06:00
So you can just wrap it inside of a label and you can do the same for the checkbox.

06:01 --> 06:14
And the nice thing about that is that all the distance that is between the checkbox and the subscribe text, that's all clickable.

06:15 --> 06:18
So one of the things, I didn't say that, I should have.

06:18 --> 06:26
is that if we go back to our top example, labels are clickable and will set the focus

06:26 --> 06:34
to the text field or select the checkbox or radio button or what have you. So I can click this label

06:34 --> 06:40
and it will automatically put the cursor in here. I can click this label and if I don't do a right

06:40 --> 06:47
click, it will check on and off the text, which is super useful, especially for people who are

06:47 --> 06:54
who have motor disabilities, for example, you want to make that clickable area as big as possible.

06:54 --> 07:06
And labels are great for that. Scrolling down. Yeah, buttons are a little bit different. So we

07:06 --> 07:13
have already seen this the search button. So there are two types of buttons in HTML. This is for

07:13 --> 07:33
for various historical reasons. Really noticeably the only button that you really should be using is the button element. The input type submit or type button, they don't really do a lot.

07:33 --> 07:41
So if you have a button type submit, that basically submits the form.

07:41 --> 07:49
So if you have a form and that does the server side submission thing, then button type submit is the right thing.

07:50 --> 07:59
And then you can label that button by putting the label, the name of the button inside of the button element.

07:59 --> 08:07
and the same goes for for like buttons that do not submit a form you want to have button type

08:07 --> 08:15
button for that now if it's a submit button or a non-submit button is not announced by assistive

08:15 --> 08:24
technology so you always have to be very explicit with your labeling and make sure that that it fits

08:24 --> 08:35
what you're doing. So as an example, I go to my website really quick. I have this preferences

08:35 --> 08:44
dialog box. Let me make this a little bit bigger for you. And that opens this modal

08:44 --> 08:52
that has a close button and a save button. And this is a submit button and this is not. But

08:52 --> 09:00
Here in this case I use close and save as my two button labels. And if we look at that in the

09:01 --> 09:09
inspector, which should open on the right, but it doesn't want to do that. There we go.

09:13 --> 09:20
Then we can see that, you know, this is a button type submit close and this is a button type submit

09:21 --> 09:27
safe because they both do something. So for example, if I change from system setting to

09:27 --> 09:35
dark mode, the close button submits that form in this case to say like reset it to

09:35 --> 09:43
not being in dark mode. So that's why this is also an input type submit. Also, it's inside

09:43 --> 09:54
of this form inside of the dialogue. So that has different, that works a little bit differently than

09:54 --> 10:03
normal forms that are not in the dialogue. Yeah, and I think that's all there is for buttons.

10:03 --> 10:15
just put like the action word in there, like submit, cancel, save, delete, stuff like that.

10:15 --> 10:22
I always like when it's an actionable word and it's not something like deletion or something

10:22 --> 10:33
like that. That makes little sense. There are not so much rules, but guidance on where to position

10:33 --> 10:42
text labels. So if you are in left to right reading language, which most of the people in

10:42 --> 10:52
this course are, I think, then you want to put the text before the field or on top of the form field

10:52 --> 10:59
if it's a text label and after the form field if it's something like a checkbox or a radio button,

11:00 --> 11:09
basically like it is in the example at the top. So here we have the first name on the left,

11:09 --> 11:14
and here we have the subscribe to newsletter to the right. And if you

11:17 --> 11:24
look at the example and you can basically like change the order.

11:26 --> 11:33
You know, I can just, can I drag and drop that? I cannot. Give me a second.

11:35 --> 11:42
Because I think once you see it, it feels like, oh yeah, this should never be like that. So

11:42 --> 11:51
if I change this around and this around, don't you want to go over there? Yes, you do. So,

11:51 --> 11:57
you know, this makes no sense at all, like having the checkbox at the right. It still works,

11:57 --> 12:03
it's still technically accessible, especially if the label text is in different length,

12:03 --> 12:07
then it's very hard to scan and you don't want to do that.