Home
Education
D/L Mode
HTML CSS JavaScript Python SQL Node.js PHP Java C++

Welcome to CSS

Start your journey in styling your web pages

Lessons

Start learning step by step

Question & Answer

Check your understanding

Interview Asked Questions

Prepare for real interviews

Quiz

Test your skills

🎨 CSS Lesson 1: Introduction to CSS

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>
    
βœ”

🎨 CSS Lesson 2: Selectors

Selectors tell CSS which HTML elements to style.

/* Element Selector */
p { color: red; }

/* Class Selector */
.myClass { font-size: 20px; }

/* ID Selector */
#myId { background: yellow; }
    
βœ”

🎨 CSS Lesson 3: Colors & Backgrounds

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 Lesson 4: Fonts & Text

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;
}
    
βœ”

🎨 CSS Lesson 5: Box Model

Every HTML element is a box. CSS controls margin, border, padding, and content.

div {
  width: 200px;
  padding: 20px;
  border: 2px solid #00ff00;
  margin: 10px;
}
    
βœ”

🎨 CSS Lesson 6: Display & Visibility

Control how elements appear and occupy space.

div {
  display: block;    /* block, inline, inline-block, flex */
  visibility: visible; /* visible, hidden */
}
    
βœ”

🎨 CSS Lesson 7: Positioning

Move elements with static, relative, absolute, fixed, sticky.

div {
  position: relative;
  top: 20px;
  left: 30px;
}
header {
  position: fixed;
  top: 0;
  width: 100%;
}
    
βœ”

🎨 CSS Lesson 8: Flexbox Basics

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 Lesson 9: Grid Basics

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;
}
    
βœ”

🎨 CSS Lesson 10: Transitions & Animations

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; }
    
βœ”

🎨 CSS Lesson 11: Colors & Backgrounds

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;
}
    
βœ”

🎨 CSS Lesson 12: Fonts & Typography

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;
}
    
βœ”

🎨 CSS Lesson 13: Borders & Outline

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;
}
    
βœ”

🎨 CSS Lesson 14: Margins & Padding

Space inside and outside elements with padding and margin.

div {
  margin: 20px;    /* space outside */
  padding: 15px;   /* space inside */
}
section {
  margin-top: 50px;
}
    
βœ”

🎨 CSS Lesson 15: Overflow & Z-index

Control content visibility and stacking order.

div {
  overflow: hidden;  /* hidden, scroll, auto */
  position: relative;
  z-index: 10;      /* stacking order */
}
.modal {
  z-index: 1000;
}
    
βœ”

🎨 CSS Lesson 16: Pseudo-classes

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; }
    
βœ”

🎨 CSS Lesson 17: Pseudo-elements

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: " 🌟"; }
    
βœ”

🎨 CSS Lesson 18: Box Shadow & Text Shadow

Add depth with shadows.

div {
  box-shadow: 0 4px 15px rgba(0,255,0,0.5);
}
h1 {
  text-shadow: 2px 2px 5px #00ff00;
}
    
βœ”

🎨 CSS Lesson 19: Media Queries (Responsive Design)

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; }
}
    
βœ”

🎨 CSS Lesson 20: Gradients

Create colorful gradients for backgrounds.

div {
  background: linear-gradient(to right, #00ff00, #001122);
}
button {
  background: radial-gradient(circle, #0d1b2a, #00ff00);
}
    
βœ”

🎨 CSS Lesson 21: Transitions

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);
}
    
βœ”

🎨 CSS Lesson 22: Animations

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;
}
    
βœ”

🎨 CSS Lesson 23: Flexbox Basics

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; }
    
βœ”

🎨 CSS Lesson 24: CSS Grid Basics

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;
}
    
βœ”

🎨 CSS Lesson 25: CSS Variables

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);
}
    
βœ”

🎨 CSS Lesson 26: Positioning

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; }
    
βœ”

🎨 CSS Lesson 27: Clipping & Masking

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);
}
    
βœ”

🎨 CSS Lesson 28: Filters & Backdrop Filters

Add blur, brightness, contrast, and more effects.

img { filter: blur(2px) brightness(120%); }
div { backdrop-filter: blur(5px) contrast(120%); }
    
βœ”

🎨 CSS Lesson 29: Blend Modes

Blend layers and images creatively.

img {
  mix-blend-mode: multiply;
}
div {
  background-color: #00ff00;
  mix-blend-mode: overlay;
}
    
βœ”

🎨 CSS Lesson 30: Advanced Responsive Techniques

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; }
}
    
πŸŽ‰ Congratulations! You have completed all CSS lessons!
Keep practicing and building amazing web pages!

🎨 CSS Questions & Answers

❓ What is CSS?
CSS (Cascading Style Sheets) is used to style and layout HTML elements. It controls colors, fonts, spacing, borders, and overall design.
❓ What are the types of CSS?
CSS can be applied in three ways:
  • Inline CSS – using the style attribute inside HTML tags.
  • Internal CSS – using <style> inside the HTML document.
  • External CSS – linking an external .css file using <link>.
❓ What is the difference between class and ID selectors in CSS?
A class selector (.) can be applied to multiple elements, while an ID selector (#) is unique and applied to only one element.
❓ What are pseudo-classes in CSS?
Pseudo-classes define a special state of an element. Example: :hover for mouse-over effect, :focus for input focus.
❓ What is the difference between relative, absolute, fixed, and sticky positioning?
  • Relative – moves element relative to its normal position.
  • Absolute – positions element relative to nearest positioned ancestor.
  • Fixed – element stays in same place even on scroll.
  • Sticky – toggles between relative and fixed depending on scroll position.
❓ What is the difference between inline, block, and inline-block elements in CSS?
  • Inline – does not start on a new line, width and height cannot be set.
  • Block – starts on a new line and takes full width, height and width can be set.
  • Inline-block – behaves like inline but allows setting width and height.
❓ What is the difference between relative units (em, rem) and absolute units (px, pt)?
Absolute units are fixed (px, pt), while relative units scale based on parent (em) or root (rem) element font size, useful for responsive design.
❓ What is the difference between visibility: hidden and display: none?
  • visibility: hidden – element is hidden but still occupies space.
  • display: none – element is removed from the layout and takes no space.
❓ What are media queries in CSS?
Media queries allow CSS to apply styles depending on device characteristics like width, height, or orientation. Example: @media (max-width: 768px) { ... }
❓ What is the difference between relative, absolute, and fixed units in CSS sizing?
Relative units (%, em, rem) scale depending on parent or root elements. Absolute units (px, pt) are fixed. Fixed units like px do not change with screen size.
❓ What is the difference between relative, absolute, and fixed positioning in CSS?
  • Relative – positioned relative to its normal position.
  • Absolute – positioned relative to the nearest positioned ancestor.
  • Fixed – positioned relative to the viewport and stays fixed on scroll.
❓ What is the difference between inline styles, internal CSS, and external CSS?
  • Inline – added directly to the element using the style attribute.
  • Internal – defined inside a <style> tag in the HTML head.
  • External – stored in a separate .css file and linked with <link> tag.
❓ What are pseudo-classes in CSS?
Pseudo-classes define a special state of an element. Example: :hover (when hovered), :focus (when focused), :first-child.
❓ What are pseudo-elements in CSS?
Pseudo-elements style specific parts of an element. Example: ::before (insert content before), ::after (insert content after), ::first-letter.
❓ What is the difference between relative and absolute units for fonts (em, rem, px)?
  • px – absolute size, fixed regardless of parent or viewport.
  • em – relative to parent element font size.
  • rem – relative to root (html) font size.
❓ What is the difference between inline, block, and inline-block elements in CSS?
  • Inline – takes only as much width as needed, does not start a new line.
  • Block – takes full width, always starts on a new line.
  • Inline-block – behaves like inline but allows setting width and height.
❓ What is the difference between relative, absolute, and fixed positioning in CSS?
  • Relative – moves relative to its normal position.
  • Absolute – positioned relative to the nearest ancestor with a position.
  • Fixed – positioned relative to the viewport, stays fixed on scroll.
❓ What is the difference between z-index and stacking context?
Z-index controls the stack order of positioned elements. Stacking context is a self-contained group of elements with a specific z-index context that affects child elements.
❓ What are media queries in CSS?
Media queries allow CSS to apply different styles depending on device characteristics, like width, height, orientation, or resolution. Example: @media (max-width: 768px) { ... }
❓ What is the difference between relative, absolute, and fixed positioning in CSS?
Relative – moves element relative to its normal position.
Absolute – positions element relative to nearest positioned ancestor.
Fixed – positions element relative to the viewport and stays fixed on scroll.
❓ What is the difference between `em`, `rem`, `%`, `px` units in CSS?
  • px – fixed pixel value.
  • % – relative to parent element.
  • em – relative to font-size of parent.
  • rem – relative to font-size of root element (html).
❓ What is the difference between `absolute`, `relative`, `sticky`, and `fixed` positioning in CSS?
  • Absolute – positioned relative to nearest positioned ancestor.
  • Relative – moves relative to its normal position.
  • Sticky – behaves like relative until a scroll position is reached, then behaves like fixed.
  • Fixed – stays in viewport regardless of scrolling.
❓ What are pseudo-classes in CSS?
Pseudo-classes define the special state of an element. Example: :hover, :first-child, :focus.
❓ What is the difference between inline, inline-block, and block elements in CSS?
Inline – only as wide as content, stays in line.
Block – takes full width, starts on new line.
Inline-block – inline behavior but allows width/height settings.
❓ What is the difference between relative, absolute, and fixed positioning in CSS?
Relative – moves relative to normal position.
Absolute – relative to nearest positioned ancestor.
Fixed – relative to viewport, stays on scroll.
❓ What is the difference between `inline`, `block`, and `flex` display types?
Inline – elements flow in a line and ignore width/height.
Block – elements take full width and start on a new line.
Flex – enables flexible layouts for children with alignment, direction, and spacing.
❓ What are media queries in CSS?
Media queries allow you to apply CSS styles based on device characteristics like width, height, orientation, and resolution. Example: @media (max-width: 768px) { ... }.
❓ What is the difference between `relative`, `absolute`, and `sticky` positioning?
Relative – moves relative to its normal position.
Absolute – positioned relative to nearest positioned ancestor.
Sticky – acts like relative until a scroll threshold, then acts like fixed.
❓ What is the difference between `inline`, `inline-block`, and `block` elements?
Inline – only as wide as content.
Inline-block – flows inline but respects width/height.
Block – takes full width and starts on a new line.
❓ What is the difference between `visibility: hidden` and `display: none`?
Visibility: hidden – hides element but still occupies space.
Display: none – removes element from the layout completely.

🎯 CSS Interview Questions

❓ What is CSS?
CSS (Cascading Style Sheets) is used to style HTML content, controlling layout, colors, fonts, and positioning.
❓ What are the different types of CSS?
Inline, Internal (in <style>), and External (linked .css file) styles.
❓ What is the difference between relative, absolute, fixed, and sticky positioning?
Relative – moves relative to normal position.
Absolute – positioned relative to nearest positioned ancestor.
Fixed – stays in the same place even on scroll.
Sticky – acts like relative until a scroll threshold, then behaves like fixed.
❓ What is the difference between inline, block, and inline-block elements?
Inline – flows in line, width/height ignored.
Block – takes full width, starts on new line.
Inline-block – flows inline but respects width/height.
❓ What are pseudo-classes and pseudo-elements?
Pseudo-classes (e.g., :hover) style elements in a specific state.
Pseudo-elements (e.g., ::before) style part of an element or insert content.
❓ What is the difference between relative, absolute, and fixed units in CSS?
Relative units (%, em, rem) depend on parent or root size.
Absolute units (px, cm) are fixed.
Fixed units remain constant regardless of parent.
❓ What are media queries?
Media queries allow CSS to adapt layouts and styles for different screen sizes and devices.
❓ What is the difference between relative, absolute, and sticky positioning?
Relative – moves relative to normal position.
Absolute – positioned relative to nearest positioned ancestor.
Sticky – sticks to position when scrolled to a threshold.
❓ What is the difference between inline styles, internal, and external CSS?
Inline – directly in HTML element.
Internal – inside <style> in head.
External – linked CSS file.
❓ What is the difference between relative, absolute, and fixed positioning in CSS?
Relative – element moves relative to its normal position.
Absolute – element positioned relative to its nearest positioned ancestor.
Fixed – element stays in the same position even when scrolling.

πŸ“ CSS Quiz: Test Your Knowledge

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?

×