CSS supports multiple color formats:
I. Named colors → p { color: red; }
II. Hexadecimal (#RRGGBB) → p { color: #ff0000; }
III. RGB → p { color: rgb(255, 0, 0); }
IV. RGBA (with transparency) → p { color: rgba(255, 0, 0, 0.5); }
V. HSL → p { color: hsl(0, 100%, 50%); }
VI. HSLA (with transparency) → p { color: hsla(0, 100%, 50%, 0.5); }
▶ Relative font sizes adapt based on parent or root size: %, em, rem, vh, vw
▶ Absolute font sizes stay fixed: px, pt, cm
✅ Best practice → Use relative units (rem/em) for accessibility.
@font-face {
font-family: 'MyFont';
src: url('myfont.woff2') format('woff2'),
url('myfont.woff') format('woff');
}
body { font-family: 'MyFont', sans-serif; }
Text Shadow:
h1 { text-shadow: 2px 2px 5px gray; }
Box Shadow:
div { box-shadow: 5px 5px 15px rgba(0,0,0,0.3); }
➡ Opacity affects the entire element (including children).
➡ RGBA transparency affects only color, not children.
Linear: background: linear-gradient(to right, red, blue);
Radial: background: radial-gradient(circle, yellow, green);
Conic: background: conic-gradient(red, yellow, green, blue);
img {
filter: grayscale(100%) blur(2px) brightness(80%);
}
Common filters: blur(), contrast(), sepia(), hue-rotate(), drop-shadow().
➡ Transition → smooth change triggered by an event.
➡ Animation → runs automatically, can loop infinitely.
button {
background: blue;
transition: background 0.5s;
}
button:hover { background: red; }
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
div { animation: fadeIn 2s infinite; }
@keyframes slide {
0% { transform: translateX(0); }
50% { transform: translateX(100px); }
100% { transform: translateX(0); }
}
.box { animation: slide 3s infinite; }
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.element { animation: fadeIn 2s ease-in-out; }
.button {
background: blue;
transition: background 0.3s, transform 0.3s;
}
.button:hover {
background: red;
transform: scale(1.1);
}
▶ translate() moves element without affecting layout.
▶ position: relative shifts element but space remains reserved.
img { clip-path: circle(50%); }
div { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
➡ Inline SVG → scalable, stylable (fill, stroke).
➡ Background image → static image, cannot be styled internally.
.text {
background: linear-gradient(to right, red, blue);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
div {
mask-image: url(mask-shape.png);
mask-repeat: no-repeat;
mask-size: cover;
}
img { mix-blend-mode: multiply; }
Common modes: multiply, screen, overlay, darken, lighten.
html { scroll-behavior: smooth; }
linear → constant speed
ease → slow start/end
ease-in → slow start
ease-out → slow end
ease-in-out → slow start & end, fast middle
div { transition: all 2s ease-in-out; }
⬅ Home