Color names let you pick colors by simple words instead of codes. This makes styling easier and faster.
Color names in CSS
Start learning this pattern below
Jump into concepts and practice - no test required
property: color-name;Use any CSS property that accepts colors, like color, background-color, or border-color.
Color names are case-insensitive, so Red and red work the same.
color: red;background-color: lightblue;border: 2px solid green;
This webpage uses color names to style the background, heading, and paragraph. You will see a light yellow page background, a dark blue text color for the body, a crimson heading, and a light green paragraph with an orange border.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Color Names Example</title> <style> body { background-color: lightyellow; color: darkblue; font-family: Arial, sans-serif; padding: 2rem; } h1 { color: crimson; } p { background-color: lightgreen; border: 3px solid orange; padding: 1rem; max-width: 400px; border-radius: 0.5rem; } </style> </head> <body> <h1>Welcome to Color Names</h1> <p>This paragraph uses color names for background, border, and text colors.</p> </body> </html>
Color names are easy but limited to about 140 standard colors.
For more precise colors, you can use hex codes or RGB values.
Always check color contrast for readability and accessibility.
Color names let you use simple words to set colors in CSS.
They work with many CSS properties like color and background-color.
Use color names for quick, readable, and browser-friendly color styling.
Practice
Solution
Step 1: Understand CSS color names
CSS supports a fixed list of color names like 'blue', 'red', 'green', etc. Names like 'bluish' or 'brightblue' are not standard.Step 2: Identify the valid color name
Among the options, only 'blue' is a recognized CSS color name.Final Answer:
blue -> Option CQuick Check:
Valid CSS color name = blue [OK]
- Using made-up color names
- Assuming any descriptive word works
- Confusing color names with CSS functions
Solution
Step 1: Recall CSS property for text color
The CSS property to set text color is 'color'. Properties like 'text-color' or 'font-color' do not exist.Step 2: Match property with color name usage
color: red; uses 'color: red;', which is correct syntax to set text color using a color name.Final Answer:
color: red; -> Option AQuick Check:
Text color property = color [OK]
- Using non-existent properties like 'text-color'
- Confusing background and text color properties
- Misspelling property names
p { color: green; }Solution
Step 1: Read the CSS rule
The CSS sets the text color of paragraph elements to 'green' using the color name.Step 2: Understand color name effect
The color name 'green' changes the text color to green in the browser.Final Answer:
Green text -> Option DQuick Check:
color: green; means green text [OK]
- Confusing property with background-color
- Assuming color names are case-sensitive
- Ignoring the CSS selector effect
div { background-color: lightbluee; }Solution
Step 1: Check the property name
The property 'background-color' is correct and valid in CSS.Step 2: Check the color name spelling
The color name 'lightbluee' is misspelled; the correct name is 'lightblue' without the extra 'e'.Final Answer:
Color name is misspelled -> Option AQuick Check:
Misspelled color name causes error [OK]
- Assuming any similar word is valid color
- Ignoring typos in color names
- Thinking semicolon or selector is wrong
Solution
Step 1: Identify text color requirement
The text should be white, so the 'color' property must be set to 'white'.Step 2: Identify background color requirement
The background should be dark red, so 'background-color' must be 'darkred'.Step 3: Match the correct CSS rule
button { color: white; background-color: darkred; } sets 'color: white;' and 'background-color: darkred;', matching the requirements exactly.Final Answer:
button { color: white; background-color: darkred; } -> Option BQuick Check:
Text white + background darkred = button { color: white; background-color: darkred; } [OK]
- Swapping text and background colors
- Using incorrect color names
- Ignoring case sensitivity of color names
