Skip to content

Instantly share code, notes, and snippets.

@fortknoxwv
Created July 21, 2021 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fortknoxwv/dc350c5c30ab648483d165d92a4ae5c0 to your computer and use it in GitHub Desktop.
Save fortknoxwv/dc350c5c30ab648483d165d92a4ae5c0 to your computer and use it in GitHub Desktop.
A cheat sheet detailing ways to apply color in CSS
<!DOCTYPE html>
<html>
<head>
<link href="styles.css" rel="stylesheet">
<title>Different CSS Color Schemes</title>
</head>
<body>
<h1>CSS Color Scheme Reference</h1>
<h2>Properties</h2>
<table>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>color</td>
<td>Sets the color for the foreground<br>i.e. the text</td>
</tr>
<tr>
<td>background-color</td>
<td>Sets the color for the background<br>i.e. the area behind the text</td>
</tr>
</tbody>
</table>
<h2>Values</h2>
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
<th>Sample Syntax</th>
</tr>
</thead>
<tbody>
<tr>
<td>named color<br>
i.e. "red", "blue", "green"</td>
<td>Pick from 140 colors with actual names
<br>No code necessary!
<br><a href='https://www.w3schools.com/cssref/css_colors.asp' target=_blank>Here is the full list</a>
</td>
<td class="syntax">color: white;</td>
</tr>
<tr>
<td>hexadecimal</td>
<td>Enter hexadecimal code for various mixed shades of red, green, and blue
<br>Each color shade has a code with numbers and letters from 0-F
<br><a href='https://www.w3schools.com/colors/colors_hexadecimal.asp' target=_blank>This site is great for finding hex codes</a>
</td>
<td class="syntax">color: #01FA3D;</td>
</tr>
<tr>
<td>rgb</td>
<td>Similar to hexadecimal, although with actual numbers representing the three basic colors
<br>The rgb value can be changed to rgba to adjust color opacity
<br><a href='https://rgbacolorpicker.com/' target=_blank>Go here to find the code for your color</a>
</td>
<td class="syntax">color: (255, 209, 38); for rgb
<br>color: (183, 229, 98, 0.6); for rgba</td>
</tr>
<tr>
<td>hsl</td>
<td>HSL is short for Hue, Saturation, and Lightness
<br>While HSL is for selecting more basic colors, users have greater control over intensity and brightness of said colors
<br>The hsl value can changed to hsla to adjust color opacity
<br><a href='http://standardista.com/webkit/ch7/hsla.html' target=_blank>Go here to find the right code for your color</a>
</td>
<td class="syntax">color: (260, 38%, 76%); for hsl
<br>color: (298, 39%, 20%, 0.5); for hsla
</td>
</tr>
</tbody>
</table>
</body>
</html>
* {
font-family: Arial, sans-serif;
}
h1,
h2 {
text-align: center;
}
h1 {
background-color: blue;
}
h2 {
background-color: cadetblue;
}
table {
margin-left: auto;
margin-right: auto;
}
th,
td{
border: 1px solid black;
}
th {
background-color: gray;
}
.syntax {
font-family: Courier, monospace;
font-weight: bold;
background-color: #46f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment