CSS allows you to add colors to text, backgrounds, borders, and other elements using various color formats.
color
– Sets the text color.background-color
– Sets the background color.border-color
– Sets the border color.red
, blue
, green
.#ff0000
(red), #00ff00
(green).rgb(255, 0, 0)
(red).rgba(0, 0, 0, 0.5)
.hsl(120, 100%, 50%)
.hsla(240, 100%, 50%, 0.3)
.h1 {
color: #0066cc;
background-color: #f0f0f0;
}
p {
color: rgba(0, 0, 0, 0.7);
}
Use tools or color pickers to choose colors that match your design. Also consider accessibility—make sure text contrasts well with the background.
body { color: red; }
body { color: #ff5733; }
body { color: rgb(255, 87, 51); }
body { color: rgba(255, 87, 51, 0.5); }
body { color: hsl(9, 100%, 60%); }
body { color: hsla(9, 100%, 60%, 0.5); }
div { background-color: lightblue; }
div { background-image: url('image.jpg'); }
div { background-image: url('image.jpg'); background-repeat: no-repeat; }
div { background-image: url('image.jpg'); background-position: center; }
div { background-image: url('image.jpg'); background-size: cover; }
div { opacity: 0.5; background-color: red; }
div { background-color: rgba(255, 0, 0, 0.5); }