Label for Radio Button Using HTML CSS

By | September 23, 2013

Label for Radio Button Using HTML CSS will makes look and feel of a radio button much better. This task is done with id and for.
ID
of the radio and its coresponding lable’s for value should be same.¬†Here is the tutorial and demo link

 

 

Label for Radio Button Using HTML CSS

Label for Radio Button Using HTML CSS

HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<html>
<body>
<input type="radio" id="1" class="rad" name="name" />
<label for="1">One</label>
<input type="radio" id="2" class="rad" name="name" />
<label for="2">Two</label>
<input type="radio" id="3" class="rad" name="name" />
<label for="3">Three</label>
</body>
</html>

 

CSS

input[type=radio]:checked + label - label of the corresponding checked radio button will have #c33

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
label
{
background-color:#9C3;
padding: 5px 12px;
}

input[type=radio]
{
display:none;
}
input[type=radio]:checked + label
{
background-color:#C33;
}

 

Full Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<html>

<head>
<style type="text/css">
label
{
background-color:#9C3;
padding: 5px 12px;
}
input[type=radio]
{
display:none;
}
input[type=radio]:checked + label
{
background-color:#C33;
}
</style>
</head>

<body>
<input type="radio" id="1" name="name" />
<label for="1">One</label>
<input type="radio" id="2" name="name" />
<label for="2">Two</label>
<input type="radio" id="3" name="name" />
<label for="3">Three</label>
</body>
</html>

7 thoughts on “Label for Radio Button Using HTML CSS

    1. tinkuriya

      Its really nice

      But i need to know the meaning of
      input[type=radio]:checked + label
      {
      background-color:#C33;
      }
      working of checked+label ????? plz

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *