Table of contents
Selecting the correct colors for your webpage can greatly improve the aesthetic appeal to your readers.
In this Blog, you'll build a set of colored markers. You'll learn different ways to set color values and how to pair colors with each other.
Basic HTML needs:
HTML elements:
Name | Definition | Syntax |
1. meta | self-closing and adds information about the page that cannot be expressed by other HTML elements. | <meta> |
HTML attributes:
Name | Definition | Syntax |
1. charset | To tell browsers how to encode characters on your page, set the charset to utf-8 . utf-8 is a universal character set that includes almost every character from all human languages. | <meta charset="utf-8"> |
2. name | to name | <meta name="viewport> |
3. content | to set your page looks the same on all devices. | <meta content="width=device-width, initial-scale=1.0"> |
CSS Properties:
Name | Definition | Syntax |
height | To set height | height: 25px; |
background-color | To set background-color | background-color:red; |
margin | To set Margin | margin: 10px auto; |
width | To set width | width: 200px; |
padding | To set left right top bottom | padding-left: 0; |
border-left-width | to set border | border-left-width:10px; |
border-left-style | to set style border | border-left-style:solid; |
border-left-color | to set color of border | border-left-color:black; |
border-left | whole together | border-left: width style color; |
box-shadow | lets you apply one or more shadows around an element. | box-shadow: offsetX offsetY color; and box-shadow: offsetX offsetY blurRadius color; and box-shadow: offsetX offsetY blurRadius spreadRadius color; |
CSS Basics:
Multiple Classes: It can be added to an element by listing them in the
class
attribute and separating them with a space.Example: <div class="marker one"></div>
additive RGB (red, green, blue)
subtractive CMYK (cyan, magenta, yellow, black)
tertiary colors, are created by combining a primary with a nearby secondary color.
CSS RGB Function (value): The CSS
rgb
function accepts values, or arguments, for red, green, and blue, and produces a color as:
rgb(red, green, blue);
example: red can be set as:
background-color: rgb(255, 0, 0);
Value between 0 and 255 | Impact |
0 | there's 0% of that color, and is black |
255 | there's 100% of that color |
255,255,0 | Yellow |
0,255,255 | cyan |
255,0,255 | magenta |
255,127,0 | orange |
0,255,127 | spring green |
127, 0, 255 | violet |
127, 255, 0 | chartreuse green (green + yellow) |
0, 127, 255 | azure (blue + cyan) |
255, 0, 127 | rose (red + magenta) |
- Hex color: The values start with a
#
character and take six characters from 0-9 and A-F. The first pair of characters represent red, the second pair represent green, and the third pair represent blue. For example,#4B5320
.
represented as: (#------) (take six characters from 0-9 and A-F)
red | green | blue |
first-pair | second-pair | third-pair |
Hex Color Value (#------) | Color |
00 | 0% of that color |
FF | 100% of that color |
#00FF00 | green |
#007F00 | Lower the intensity of green |
- HSL color model: hue, saturation, and lightness, is another way to represent colors.
Syntax: hsl(hue, sat%, lig%);
Name | Value | Color |
hue | 0 to 360 (number ) | - |
Saturation | 0 to 100 ( Percentage ) You must add the percent sign % to the saturation. | 0% - grey, 100% - pure color |
Lightness | 0 to 100 ( % ) You must add the percent sign % to the lightness | 0% - complete black, 100% - complete white, 50% - neutral |
Gradient: A gradient is when one color transitions into another.
\> Linear-gradient Function: lets you control the direction of the transition along a line, and which colors are used.Defaults:
a. You won't see gradient yet because the
linear-gradient
function needs at least two color arguments to work.b.
gradientDirection
argument is provided to thelinear-gradient
function, it arranges colors from top to bottom, or along a 180 degree line, by default.c. Color stops, default, o% - first color argument,50% - second color argument, 100% - third color argument.
Explanation, internal working: actually creates an
image
element, and is usually paired with thebackground
property which can accept an image as a value.
Syntax: linear-gradient(gradientDirection, color1, color2, ...);
' gradientDirection
is the direction of the line used for the transition.
' color1
and color2
are color arguments, which are the colors that will be used in the transition itself. These can be any type of color, including color keywords, hex, rgb
, or hsl
.
Example 1:
.red {
background: linear-gradient(90deg);
}
Example 2:
.red {
background: linear-gradient(90deg, rgb(255,0,0));
}
Example 3: Using Hexa colors
.green {
background: linear-gradient(180deg, #55680D, #71F53E,#116C31);
}
Example 4: hsl Function
.blue {
background: linear-gradient(hsl(186, 76%, 16%), hsl(223, 90%, 60%),hsl(240,56%,42%));
}
Opacity: describes how opaque, or non-transparent, something is. For example, a solid wall is opaque, and no light can pass through. But a drinking glass is much more transparent, and you can see through the glass to the other side.
alpha channel: Similar to the
opacity
property, the alpha channel controls how transparent or opaque a color is. We can also use an alpha channel withhsl
andhex
colors.rgba function: The
rgba
function works just like thergb
function, but takes one more number from0
to1.0
for the alpha channel.Syntax: rgba(redValue, greenValue, blueValue, alphaValue);
hsla function: The
hsla
function works just like thehsl
function, but takes one more number from0
to1.0
for the alpha channel.Syntax: hsla(hueValue, saturationValue, lightnessValue, alphaValue);