Colors, Backgrounds and Link Styles
What Is It?
CSS can change text colors, backgrounds, and the way links look when people use them.
What the Tags Mean
color: text color.background-color: background color.:hover: when a pointer is over an element.:focus-visible: when a control needs a visible focus mark.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Colors, Backgrounds and Link Styles</title>
</head>
<body>
<p style="color: navy; background-color: lightyellow">A colorful note</p>
</body>
</html>Browser preview
What you see: The note has navy text on a pale yellow background.
Example 2: Another Use
Make a link show feedback when someone points at it or uses the keyboard.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Colors, Backgrounds and Link Styles</title>
<style>
a { color: navy; }
a:hover { color: darkred; }
a:focus-visible { outline: 2px solid blue; }
</style>
</head>
<body>
<a href="#details">Read details</a>
<h2 id="details">Details</h2>
</body>
</html>Browser preview
Simple Tip
Colors can use names, HEX (#0000ff), RGB (rgb(0 0 255)), or HSL (hsl(240 100% 50%)). Keep text easy to read.
Try It Yourself
Give a paragraph a different text color and background.