{
"$schema": "../schemas/code-crispies-module-schema.json",
"id": "html-datalist",
"title": "Datalist",
"description": "Provide suggestions for text inputs without JavaScript",
"mode": "html",
"difficulty": "beginner",
"lessons": [
{
"id": "datalist-basic",
"title": "Input with Suggestions",
"description": "The <datalist> element provides autocomplete suggestions for inputs. Connect it using the list attribute on the input matching the datalist's id.
Users can still type freely - suggestions are just helpers!",
"task": "Create a browser selector: 1. Add a <label> saying 'Browser:' 2. Add an <input> with list=\"browsers\" 3. Add a <datalist id=\"browsers\"> with options for Chrome, Firefox, and Safari",
"previewHTML": "",
"previewBaseCSS": "body { font-family: system-ui; padding: 20px; } label { display: block; margin-bottom: 8px; font-weight: 500; } input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; } input:focus { outline: 2px solid #1976d2; border-color: transparent; }",
"sandboxCSS": "",
"initialCode": "",
"solution": "\n\n",
"previewContainer": "preview-area",
"validations": [
{
"type": "element_exists",
"value": "datalist",
"message": "Add a <datalist> element"
},
{
"type": "attribute_value",
"value": { "selector": "input", "attr": "list", "value": "browsers" },
"message": "Connect the input to datalist using list=\"browsers\""
},
{
"type": "element_count",
"value": { "selector": "option", "min": 3 },
"message": "Add at least 3 <option> elements inside <datalist>"
},
{
"type": "element_exists",
"value": "label",
"message": "Add a <label> for the input"
}
]
},
{
"id": "datalist-countries",
"title": "Country Selector",
"description": "Datalists work great for long lists like countries. Users can type to filter suggestions instantly.
The value attribute is what gets entered, and you can add display text after it.",
"task": "Create a country input: 1. Add a <label> saying 'Country:' 2. Add an <input> with list=\"countries\" 3. Add a <datalist id=\"countries\"> with at least 4 country options",
"previewHTML": "",
"previewBaseCSS": "body { font-family: system-ui; padding: 30px; background: linear-gradient(135deg, #e0f7fa 0%, #b2ebf2 100%); min-height: 100vh; margin: 0; box-sizing: border-box; } label { display: block; margin-bottom: 10px; font-weight: 600; color: #00695c; } input { width: 100%; padding: 12px 15px; border: 2px solid #26a69a; border-radius: 8px; font-size: 16px; background: white; } input:focus { outline: none; border-color: #00695c; box-shadow: 0 0 0 3px rgba(38,166,154,0.2); }",
"sandboxCSS": "",
"initialCode": "",
"solution": "\n\n",
"previewContainer": "preview-area",
"validations": [
{
"type": "element_exists",
"value": "datalist",
"message": "Add a <datalist> element"
},
{
"type": "attribute_value",
"value": { "selector": "datalist", "attr": "id", "value": "countries" },
"message": "Set id=\"countries\" on the datalist"
},
{
"type": "attribute_value",
"value": { "selector": "input", "attr": "list", "value": "countries" },
"message": "Connect the input using list=\"countries\""
},
{
"type": "element_count",
"value": { "selector": "option", "min": 4 },
"message": "Add at least 4 country options"
}
]
}
]
}