{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "colors-backgrounds", "title": "CSS Colors", "description": "Learn how to apply colors to text and backgrounds using CSS properties.", "difficulty": "beginner", "lessons": [ { "id": "colors-1", "title": "Background Color", "description": "Color is one of the most powerful tools in web design. It creates visual hierarchy, conveys meaning, and establishes brand identity. CSS provides multiple ways to specify colors.

CSS named colors: CSS includes 147 named colors like steelblue, coral, gold, and tomato. These are easy to remember and read.

The background-color property: Sets the fill color behind an element's content and padding areas. The color extends to the edge of the element's border.

.box {\n  background-color: lightblue;\n}
", "task": "Set background-color to lightcyan on .box.", "previewHTML": "
Background Demo
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; } .box { padding: 1rem; border: 2px solid steelblue; }", "sandboxCSS": "", "codePrefix": ".box {\n ", "initialCode": "", "codeSuffix": "\n}", "previewContainer": "preview-area", "validations": [ { "type": "property_value", "value": { "property": "background-color", "expected": "lightcyan" }, "message": "Set background-color: lightcyan" } ] }, { "id": "colors-2", "title": "Text Color", "description": "The color property sets the color of text content. Good contrast between text and background is essential for readability.", "task": "Set color to darkslategray on .box.", "previewHTML": "
Color & Contrast
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; } .box { padding: 1rem; background-color: lightcyan; border: 2px solid steelblue; }", "sandboxCSS": "", "codePrefix": ".box {\n ", "initialCode": "", "codeSuffix": "\n}", "previewContainer": "preview-area", "validations": [ { "type": "property_value", "value": { "property": "color", "expected": "darkslategray" }, "message": "Set color: darkslategray" } ] }, { "id": "colors-3", "title": "Border Color", "description": "Borders can have their own color using border-color, or you can specify color in the border shorthand.", "task": "Set border-color to coral on .box.", "previewHTML": "
Border Color
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; } .box { padding: 1rem; background-color: seashell; border: 4px solid gray; }", "sandboxCSS": "", "codePrefix": ".box {\n ", "initialCode": "", "codeSuffix": "\n}", "previewContainer": "preview-area", "validations": [ { "type": "property_value", "value": { "property": "border-color", "expected": "coral" }, "message": "Set border-color: coral" } ] }, { "id": "colors-4", "title": "Color Formats", "description": "Besides named colors, CSS supports hex codes (#ff6347), RGB (rgb(255, 99, 71)), and HSL (hsl(9, 100%, 64%)) formats.", "task": "Set background-color to #f0e68c (khaki in hex) on .box.", "previewHTML": "
Hex Color
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; } .box { padding: 1rem; border: 2px solid olive; }", "sandboxCSS": "", "codePrefix": ".box {\n ", "initialCode": "", "codeSuffix": "\n}", "previewContainer": "preview-area", "validations": [ { "type": "property_value", "value": { "property": "background-color", "expected": "#f0e68c" }, "message": "Set background-color: #f0e68c" } ] } ] }