Back

Radio

1 
2<div class="rating">
3 <input value="5" name="rating" id="star5" type="radio" />
4 <label title="5 stars" for="star5">
5 <svg
6 stroke-linejoin="round"
7 stroke-linecap="round"
8 stroke-width="2"
9 stroke="#000000"
10 fill="none"
11 viewBox="0 0 24 24"
12 height="35"
13 width="35"
14 xmlns="http://www.w3.org/2000/svg"
15 class="svgOne"
16 >
17 <polygon
18 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
19 ></polygon>
20 </svg>
21 <svg
22 stroke-linejoin="round"
23 stroke-linecap="round"
24 stroke-width="2"
25 stroke="#000000"
26 fill="none"
27 viewBox="0 0 24 24"
28 height="35"
29 width="35"
30 xmlns="http://www.w3.org/2000/svg"
31 class="svgTwo"
32 >
33 <polygon
34 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
35 ></polygon>
36 </svg>
37 <div class="ombre"></div>
38 </label>
39 
40 <input value="4" name="rating" id="star4" type="radio" />
41 <label title="4 stars" for="star4">
42 <svg
43 stroke-linejoin="round"
44 stroke-linecap="round"
45 stroke-width="2"
46 stroke="#000000"
47 fill="none"
48 viewBox="0 0 24 24"
49 height="35"
50 width="35"
51 xmlns="http://www.w3.org/2000/svg"
52 class="svgOne"
53 >
54 <polygon
55 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
56 ></polygon>
57 </svg>
58 <svg
59 stroke-linejoin="round"
60 stroke-linecap="round"
61 stroke-width="2"
62 stroke="#000000"
63 fill="none"
64 viewBox="0 0 24 24"
65 height="35"
66 width="35"
67 xmlns="http://www.w3.org/2000/svg"
68 class="svgTwo"
69 >
70 <polygon
71 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
72 ></polygon>
73 </svg>
74 <div class="ombre"></div>
75 </label>
76 
77 <input value="3" name="rating" id="star3" type="radio" />
78 <label title="3 stars" for="star3">
79 <svg
80 stroke-linejoin="round"
81 stroke-linecap="round"
82 stroke-width="2"
83 stroke="#000000"
84 fill="none"
85 viewBox="0 0 24 24"
86 height="35"
87 width="35"
88 xmlns="http://www.w3.org/2000/svg"
89 class="svgOne"
90 >
91 <polygon
92 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
93 ></polygon>
94 </svg>
95 <svg
96 stroke-linejoin="round"
97 stroke-linecap="round"
98 stroke-width="2"
99 stroke="#000000"
100 fill="none"
101 viewBox="0 0 24 24"
102 height="35"
103 width="35"
104 xmlns="http://www.w3.org/2000/svg"
105 class="svgTwo"
106 >
107 <polygon
108 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
109 ></polygon>
110 </svg>
111 <div class="ombre"></div>
112 </label>
113 
114 <input value="2" name="rating" id="star2" type="radio" />
115 <label title="2 stars" for="star2">
116 <svg
117 stroke-linejoin="round"
118 stroke-linecap="round"
119 stroke-width="2"
120 stroke="#000000"
121 fill="none"
122 viewBox="0 0 24 24"
123 height="35"
124 width="35"
125 xmlns="http://www.w3.org/2000/svg"
126 class="svgOne"
127 >
128 <polygon
129 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
130 ></polygon>
131 </svg>
132 <svg
133 stroke-linejoin="round"
134 stroke-linecap="round"
135 stroke-width="2"
136 stroke="#000000"
137 fill="none"
138 viewBox="0 0 24 24"
139 height="35"
140 width="35"
141 xmlns="http://www.w3.org/2000/svg"
142 class="svgTwo"
143 >
144 <polygon
145 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
146 ></polygon>
147 </svg>
148 <div class="ombre"></div>
149 </label>
150 
151 <input value="1" name="rating" id="star1" type="radio" />
152 <label title="1 star" for="star1">
153 <svg
154 stroke-linejoin="round"
155 stroke-linecap="round"
156 stroke-width="2"
157 stroke="#000000"
158 fill="none"
159 viewBox="0 0 24 24"
160 height="35"
161 width="35"
162 xmlns="http://www.w3.org/2000/svg"
163 class="svgOne"
164 >
165 <polygon
166 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
167 ></polygon>
168 </svg>
169 <svg
170 stroke-linejoin="round"
171 stroke-linecap="round"
172 stroke-width="2"
173 stroke="#000000"
174 fill="none"
175 viewBox="0 0 24 24"
176 height="35"
177 width="35"
178 xmlns="http://www.w3.org/2000/svg"
179 class="svgTwo"
180 >
181 <polygon
182 points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
183 ></polygon>
184 </svg>
185 <div class="ombre"></div>
186 </label>
187</div>
1 
2.rating {
3 display: flex;
4 flex-direction: row-reverse;
5 gap: 0.3rem;
6 transform-style: preserve-3d;
7 perspective: 1000px;
8}
9.rating input {
10 display: none;
11}
12 
13.rating label .svgOne {
14 stroke: #ccc;
15 fill: rgba(255, 217, 0, 0);
16 transition:
17 stroke 0.5s ease,
18 fill 0.5s ease;
19}
20 
21.rating label .svgTwo {
22 position: absolute;
23 top: -1px;
24 fill: gold;
25 stroke: rgba(255, 217, 0, 0);
26 opacity: 0;
27 transition:
28 stroke 0.5s ease,
29 fill 0.5s ease,
30 opacity 0.5s ease;
31}
32 
33.rating label {
34 position: relative;
35 cursor: pointer;
36 display: flex;
37 flex-direction: column;
38 justify-content: center;
39 align-items: center;
40 gap: 3px;
41 transition: all 0.5s ease;
42}
43 
44/* Étoiles sélectionnées ou survolées */
45.rating label:hover .svgOne,
46.rating label:hover ~ label .svgOne {
47 stroke: gold;
48}
49 
50.rating input:checked ~ label .svgOne {
51 stroke: #cccccc00;
52}
53 
54.rating input:checked ~ label .svgTwo {
55 transform: rotateX(0deg) rotateY(0deg) translateY(0px);
56 opacity: 1;
57 animation: displayStar 0.5s cubic-bezier(0.75, 0.41, 0.82, 1.2);
58}
59 
60@keyframes displayStar {
61 0% {
62 transform: rotateX(100deg) rotateY(100deg) translateY(10px);
63 }
64 100% {
65 transform: rotateX(0deg) rotateY(0deg) translateY(0px);
66 }
67}
68 
69.ombre {
70 background: radial-gradient(
71 ellipse closest-side,
72 rgba(0, 0, 0, 0.24),
73 rgba(0, 0, 0, 0)
74 );
75 width: 30px;
76 height: 8px;
77 opacity: 0;
78 transition: opacity 0.6s ease 0.2s;
79}
80 
81/* Étoiles sélectionnées ou survolées */
82.rating label:hover .ombre,
83.rating label:hover ~ label .ombre {
84 opacity: 0.3;
85}
86 
87.rating input:checked ~ label .ombre {
88 opacity: 1;
89}
90 
91/* Animation de secousse uniquement au hover */
92.rating label:hover .svgTwo:hover {
93 animation:
94 chackStar 0.6s ease-out,
95 displayStar none 1s;
96}
97 
98@keyframes chackStar {
99 0% {
100 transform: rotate(0deg);
101 }
102 20% {
103 transform: rotate(-20deg);
104 }
105 50% {
106 transform: rotate(20deg);
107 }
108 80% {
109 transform: rotate(-20deg);
110 }
111 100% {
112 transform: rotate(0deg);
113 }
114}

MIT License

Copyright © 2026 Lu2ovic (Ludovic H)


Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:


The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.