Start your journey in styling your web pages
Start learning step by step
Check your understanding
Prepare for real interviews
Test your skills
CSS (Cascading Style Sheets) styles your HTML elements and makes your website look amazing.
/* Link CSS to HTML */ <link rel="stylesheet" href="style.css"> /* Example */ <h1>Hello</h1> <p>This is styled text</p>
Selectors tell CSS which HTML elements to style.
/* Element Selector */ p { color: red; } /* Class Selector */ .myClass { font-size: 20px; } /* ID Selector */ #myId { background: yellow; }
Learn how to change colors, backgrounds, and gradients.
body {
background-color: #0d1b2a;
color: #00ff00;
}
h1 {
background: linear-gradient(90deg, #00ff00, #00ccff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
CSS controls font family, size, weight, and text effects.
p {
font-family: 'Share Tech Mono', monospace;
font-size: 16px;
font-weight: bold;
text-shadow: 0 0 5px #00ff00;
}
Every HTML element is a box. CSS controls margin, border, padding, and content.
div {
width: 200px;
padding: 20px;
border: 2px solid #00ff00;
margin: 10px;
}
Control how elements appear and occupy space.
div {
display: block; /* block, inline, inline-block, flex */
visibility: visible; /* visible, hidden */
}
Move elements with static, relative, absolute, fixed, sticky.
div {
position: relative;
top: 20px;
left: 30px;
}
header {
position: fixed;
top: 0;
width: 100%;
}
Flexbox helps align items in rows or columns easily.
.container {
display: flex;
flex-direction: row; /* row or column */
justify-content: center; /* start, end, center, space-between */
align-items: center; /* top, center, bottom */
}
CSS Grid helps create 2D layouts with rows and columns.
.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-gap: 10px;
}
.item {
background: #00ff00;
}
Add smooth effects and animations to your elements.
button {
background: #00ff00;
transition: 0.3s; /* smooth hover */
}
button:hover {
background: #00cc00;
transform: scale(1.1);
}
@keyframes blink {
0% { opacity: 0; }
50% { opacity: 1; }
100% { opacity: 0; }
}
span.blink { animation: blink 1s infinite; }
Use colors, gradients, and background images to style elements.
div {
background-color: #0d1b2a;
color: #00ff00;
background-image: linear-gradient(to right, #0d1b2a, #001122);
background-size: cover;
}
Control font family, size, weight, line height, and letter spacing.
p {
font-family: 'Share Tech Mono', monospace;
font-size: 16px;
font-weight: 600;
line-height: 1.5;
letter-spacing: 1px;
text-transform: uppercase;
}
Add borders, rounded corners, and outlines to elements.
div {
border: 2px solid #00ff00;
border-radius: 10px; /* rounded corners */
outline: 3px dashed #00cc00;
outline-offset: 5px;
}
Space inside and outside elements with padding and margin.
div {
margin: 20px; /* space outside */
padding: 15px; /* space inside */
}
section {
margin-top: 50px;
}
Control content visibility and stacking order.
div {
overflow: hidden; /* hidden, scroll, auto */
position: relative;
z-index: 10; /* stacking order */
}
.modal {
z-index: 1000;
}
Style elements on hover, focus, active states, etc.
a:hover { color: #00cc00; }
input:focus { border-color: #00ff00; }
button:active { transform: scale(0.95); }
li:nth-child(odd) { background: #001122; }
Add content before or after elements and style parts of text.
p::first-letter { font-size: 2rem; color: #00ff00; }
p::before { content: "π₯ "; }
p::after { content: " π"; }
Add depth with shadows.
div {
box-shadow: 0 4px 15px rgba(0,255,0,0.5);
}
h1 {
text-shadow: 2px 2px 5px #00ff00;
}
Make your page look good on all devices.
@media screen and (max-width: 768px) {
body { background-color: #001122; }
.container { flex-direction: column; }
}
@media screen and (min-width: 769px) {
.container { flex-direction: row; }
}
Create colorful gradients for backgrounds.
div {
background: linear-gradient(to right, #00ff00, #001122);
}
button {
background: radial-gradient(circle, #0d1b2a, #00ff00);
}
Smoothly animate property changes on hover or action.
button {
background-color: #0d1b2a;
color: #00ff00;
transition: background-color 0.5s, transform 0.3s;
}
button:hover {
background-color: #00cc00;
transform: scale(1.1);
}
Create keyframe animations for dynamic effects.
@keyframes slideIn {
0% { transform: translateX(-100%); opacity: 0; }
100% { transform: translateX(0); opacity: 1; }
}
div {
animation: slideIn 1s ease-in-out forwards;
}
Use flexbox to align and distribute elements efficiently.
.container {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.item { flex: 1; margin: 10px; }
Create grid layouts with rows, columns, and gaps.
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
}
.grid-item {
background-color: #0d1b2a;
color: #00ff00;
padding: 20px;
}
Use custom properties to simplify color and style management.
:root {
--main-color: #00ff00;
--bg-color: #0d1b2a;
--padding: 15px;
}
div {
background-color: var(--bg-color);
color: var(--main-color);
padding: var(--padding);
}
Use static, relative, absolute, fixed, and sticky positions.
div { position: relative; top: 10px; left: 20px; }
.modal { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
header { position: sticky; top: 0; background: #001122; }
Create complex shapes and hide overflow creatively.
img {
clip-path: circle(50% at 50% 50%);
}
div {
-webkit-mask-image: linear-gradient(to bottom, transparent, black);
}
Add blur, brightness, contrast, and more effects.
img { filter: blur(2px) brightness(120%); }
div { backdrop-filter: blur(5px) contrast(120%); }
Blend layers and images creatively.
img {
mix-blend-mode: multiply;
}
div {
background-color: #00ff00;
mix-blend-mode: overlay;
}
Combine flex, grid, media queries, and variables for pro layouts.
:root { --gap: 20px; }
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: var(--gap);
}
@media screen and (max-width: 600px) {
.container { grid-template-columns: 1fr; }
}
:hover for mouse-over effect, :focus for input focus.
@media (max-width: 768px) { ... }
:hover (when hovered), :focus (when focused), :first-child.
::before (insert content before), ::after (insert content after), ::first-letter.
@media (max-width: 768px) { ... }
:hover, :first-child, :focus.
@media (max-width: 768px) { ... }.
1. What does CSS stand for?
2. Which HTML tag is used to link an external CSS file?
3. Which property is used to change the text color in CSS?
4. Which CSS property controls the text size?
5. How do you make a list not display bullets in CSS?
6. Which property is used to change the background color?
7. Which property is used to change the font of an element?
8. How do you select an element with id "demo" in CSS?
9. How do you select elements with class "example" in CSS?
10. Which property is used to change the left margin of an element?
11. What is the default position property of an element?
12. Which CSS property is used to control the transparency of an element?
13. Which property is used to make text bold?
14. Which CSS property is used to add spacing inside an element?