A. Todo lo que hay

Este es un ejemplo típico de un formulario HTML.

Salida

Ábrelo en otra pestaña.

Revísalo en gilpgedit.

1<!DOCTYPE html>
2<html lang="es">
3
4<head>
5
6 <meta charset="UTF-8">
7 <title>Formulario</title>
8 <meta name="viewport"
9 content="width=device-width">
10
11 <style>
12 body {
13 font-family: sans-serif;
14 }
15
16 form {
17 max-width: 900px;
18 margin-inline: auto;
19 }
20
21 label,
22 legend {
23 font-weight: bold;
24 }
25
26 fieldset label {
27 font-weight: normal;
28 }
29
30 label:has(:not([type="radio"]):required)::before {
31 content: "✳ ";
32 }
33
34 label:has(:not([type="radio"]):invalid)::before {
35 content: "❌ ";
36 }
37
38 label:has(:not([type="radio"]):invalid:required)::before {
39 content: "✳ ❌ ";
40 }
41
42 label output,
43 label input:not([type="checkbox"], [type="radio"], [type="range"]),
44 label select,
45 label textarea {
46 display: block;
47 box-sizing: border-box;
48 width: 100%;
49 }
50
51 label:has([type="range"]) {
52 white-space: pre-wrap;
53 }
54
55 fieldset {
56 box-sizing: border-box;
57 }
58
59 fieldset p {
60 margin-block: 0.5rem;
61 }
62
63 fieldset label:has(:invalid)::after {
64 content: "❌";
65 }
66
67 legend:has(~p :required)::before {
68 content: "✳ ";
69 }
70
71 input[name="temperatura2"] {
72 writing-mode: vertical-lr;
73 }
74 </style>
75
76</head>
77
78<body>
79
80 <form id="forma">
81
82 <h1>Formulario</h1>
83
84 <p>
85 <label>
86 Nombre
87 <output name="nombre">Pp</output>
88 </label>
89 </p>
90
91 <p>
92 <label accesskey="A">
93 Apellidos
94 <input name="apellidos" type="text" placeholder="ej. Pérez López"
95 required>
96 <small>Los apellidos de tu familia</small>
97 </label>
98 </p>
99
100 <input name="clave" type="hidden" value="">
101
102 <p>
103 <label>
104 Restaurante favorito
105 <input name="apellidos" type="text" value="La cabaña del Tio Jese">
106 </label>
107 </p>
108
109 <p>
110 <label>
111 Número telefónico
112 <input name="telefono" type="tel">
113 </label>
114 </p>
115
116 <p>
117 <label>
118 Número de tarjeta
119 <input name="tarjeta" type="text" pattern="\d{14,19}" inputmode="numeric">
120 <small>14 a 19 letras o caracteres.</small>
121 </label>
122 </p>
123
124 <p>
125 <label>
126 Sitio personal
127 <input name="sitio" type="url" list="sitios">
128 </label>
129 </p>
130 <datalist id="sitios">
131 <option>https://facebook.com</option>
132 <option>https://google.com</option>
133 <option>https://tiktok.com</option>
134 <option>https://youtube.com</option>
135 </datalist>
136 <p>
137 <label>
138 Email para quejas
139 <input name="quejas" type="email">
140 </label>
141 </p>
142
143 <p>
144 <label>
145 Match
146 <input name="match" type="password" required pattern="\w{4,7}">
147 </label>
148 <small>4 a 7 letras o caracteres.</small>
149 </p>
150
151 <p>
152 <label>
153 Próximo día festivo
154 <input name="proximo" type="date">
155 </label>
156 </p>
157
158 <p>
159 <label>
160 Próximo día libre
161 <input name="libre" type="date" value="2025-02-14" min="2025-01-01"
162 max="2025-06-01" step="2">
163 </label>
164 </p>
165
166 <p>
167 <label>
168 Mes
169 <input name="mes" type="month" value="2025-04" min="2025-01" max="2025-12"
170 step="3">
171 </label>
172 </p>
173
174 <p>
175 <label>
176 Semana de vacaciones
177 <input name="vacaciones" type="week" value="2025-W05" min="2025-W01"
178 max="2025-W54" step="2">
179 </label>
180 </p>
181
182 <p>
183 <label>
184 Hora de la reunión
185 <input name="horaReunion" type="time" value="15:30" min="07:00"
186 max="17:30" step="1800">
187 </label>
188 </p>
189
190 <p>
191 <label>
192 Fecha y hora local
193 <input name="nacimiento" type="datetime-local" value="2025-03-18T15:00"
194 min="2025-01-01T10:00" max="2025-12-31T22:00" step="3600">
195 </label>
196 </p>
197
198 <p>
199 <label>
200 Altura
201 <input name="altura" type="number" min="0.5" max="3.0" step="0.01">
202 </label>
203 </p>
204
205 <p>
206 <label>
207 Temperatura
208 -50 <input name="temperatura" type="range" min="-50" max="80" step="10"
209 value="20"> 80</label>
210 </p>
211
212 <p>
213 <label>
214 Temperatura 2
215 -50
216 <input name="temperatura2" type="range" min="-50" max="80"
217 value="20" list="temperaturas">
218 80</label>
219 </p>
220 <datalist id="temperaturas">
221 <option value="-50">Congelado</option>
222 <option value="-30"></option>
223 <option value="0"></option>
224 <option value="30"></option>
225 <option value="50"></option>
226 <option value="80">Quemándose</option>
227 </datalist>
228 <p>
229 <label>
230 Color
231 <input name="color" type="color" colorspace="limited-srgb" value="#00ff00">
232 </label>
233 </p>
234
235 <p>
236 <label>
237 Tarea
238 <input name="tarea" type="file" accept="image/*,application/pdf">
239 </label>
240 </p>
241
242 <p>
243 <label>
244 <input name="aprobado" type="checkbox">
245 Aprobado
246 </label>
247 </p>
248
249 <fieldset>
250 <legend>Pasatiempos</legend>
251 <p>
252 <label>
253 <input type="checkbox" name="pasatiempos[]" value="fut">
254 Futbol
255 </label>
256 </p>
257 <p>
258 <label>
259 <input type="checkbox" name="pasatiempos[]" value="chess" checked>
260 Ajedrez
261 </label>
262 </p>
263 <p>
264 <label>
265 <input type="checkbox" name="pasatiempos[]" value="basket" checked>
266 Basketbol
267 </label>
268 </p>
269 </fieldset>
270
271 <fieldset>
272 <legend>Madrugador</legend>
273 <p>
274 <label><input type="radio" name="madrugador" value="si" checked>Si</label>
275 <label><input type="radio" name="madrugador" value="no">No</label>
276 </p>
277 </fieldset>
278
279 <fieldset>
280 <legend>Tamaño</legend>
281 <p>
282 <label>
283 <input type="radio" name="tamano" value="grande" required>
284 Grande
285 </label>
286 </p>
287 <p>
288 <label>
289 <input type="radio" name="tamano" value="mediano">
290 Mediano
291 </label>
292 </p>
293 <p>
294 <label>
295 <input type="radio" name="tamano" value="chico">
296 Chico
297 </label>
298 </p>
299 </fieldset>
300
301 <p>
302 <label>
303 Género Musical
304 <select name="generoMusical" required>
305 <option value="">Sin selección</option>
306 <option value="pop">Pop</option>
307 <option value="reg">Reguetón</option>
308 </select>
309 </label>
310 </p>
311
312 <p>
313 <label>
314 Géneración
315 <select name="generacion" value="Z">
316 <option value="boom">Baby Boom</option>
317 <option value="X">X</option>
318 <option value="">Sin selección</option>
319 <option value="Y">Millenoals</option>
320 <option value="Z">Z</option>
321 <option value="alfa">Alfa</option>
322 </select>
323 </label>
324 </p>
325
326 <p>
327 <label>
328 Género
329 <select name="genero">
330 <option value="masculino">Masculino</option>
331 <option value="femenino" selected>Femenino</option>
332 <option value="">-- Seleccionar --</option>
333 <optgroup label="Otros">
334 <option value="nodecir">Prefiero no decirlo</option>
335 <option value="nobinario">No binario</option>
336 </optgroup>
337 </select>
338 </label>
339 </p>
340
341 <p>
342 <label>
343 Bebidas
344 <select name="bebidas[]" multiple size="3">
345 <option value="cafe" selected>Café</option>
346 <option value="agua" selected>Agua</option>
347 <option value="limonada">Limonada</option>
348 </select>
349 </label>
350 </p>
351
352 <p>
353 <label>
354 Mi camino desde casa
355 <textarea name="camino" required rows="10" cols="25"></textarea>
356 </label>
357 </p>
358
359 <p>
360 <label>
361 Mi opinión sobre la comida mexicana
362 <textarea name="opinion" rows="10" cols="25">Es muy rica</textarea>
363 </label>
364 </p>
365
366 <p><small>✳ Obligatorio</small></p>
367
368 <p>
369 <button type="submit">Procesar</button>
370 <button type="reset">Reiniciar</button>
371 </p>
372
373 </form>
374
375</body>
376
377</html>

Solo para los más rudos

skip_previous skip_next