SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 32 of 35

CSS Filters Tutorial — Blur, Grayscale, Sepia & More

4 min read · Free · No login needed

Open any photo app and tap a filter: one tap makes the photo black-and-white, another makes it warm and old-looking, another softens it into a blur. CSS gives you the same power in a single line of code. The filter property applies a visual effect to a whole element — an image, a box, even a block of text — without changing the element itself or anything around it.

Diagram — see how it fits together
Diagram: CSS Filters

What a filter does

A filter changes the pixels of an element after it has been drawn. The element keeps its size and position; only its appearance changes. This is why filters are so easy to use: you do not rearrange the page, you just restyle what is already there. One important rule — a filter on a parent affects everything inside it too, and a child cannot undo its parent's filter.

The filter functions

Each filter is a function with a value. The most useful ones are:

.soft    { filter: blur(3px); }
.bright  { filter: brightness(1.5); }
.old     { filter: sepia(80%); }
.grey    { filter: grayscale(100%); }
.strong  { filter: contrast(150%); }

blur() softens the edges, measured in pixels. brightness() takes a number — 1 is normal, 1.5 is brighter, 0.5 is darker. sepia(), grayscale() and contrast() take percentages. There are more — saturate() for colour intensity, hue-rotate() for shifting colours around the wheel, and invert() for a photo negative — but the five above cover most real designs.

Combining filters and the hover trick

Filters combine in one line, separated by spaces: filter: grayscale(100%) contrast(120%); gives a punchy black-and-white photo. The classic portfolio trick is a photo that starts in grayscale and returns to colour on hover: img { filter: grayscale(100%); } and img:hover { filter: grayscale(0%); }. Add a transition and the colour fades in smoothly instead of snapping. There is also backdrop-filter, which blurs whatever is behind an element — the frosted-glass effect you see on modern menus and cards.

Note: A filter on a parent applies to the parent and all its children together, as one flat picture. You cannot put a filter on a box and then remove it from a heading inside that box — the heading is already part of the filtered picture.
Tip: Use filters for states, not just decoration. A disabled button in grayscale, a photo that sharpens on hover, a card that brightens when selected — filters communicate meaning at a glance, which is exactly what good design does.

Common mistakes

  • Writing two filter lines in one rule — the second one wins; combine them into a single line instead.
  • Forgetting the unit — blur(3) without px and sepia(80) without % are both invalid.
  • Using brightness(150%) — brightness takes a plain number like 1.5, not a percentage.
  • Trying to un-filter a child of a filtered parent — the child is already inside the filtered picture and cannot escape it.
  • Overdoing blur on large areas — a heavy blur on a big image is slow to draw on cheap phones, so keep blurs small.

Remember

  • filter changes an element's pixels, not its size or position.
  • blur() softens, brightness() lightens or darkens, grayscale() removes colour, sepia() ages a photo.
  • Combine filters in one line, separated by spaces.
  • A parent's filter covers all its children, and a child cannot undo it.
  • Grayscale-to-colour on hover is the classic portfolio trick — add a transition for a smooth fade.

Example explained

  • .blur { filter: blur(3px); } — the first box is softly blurred, like a photo taken slightly out of focus.
  • .bright { filter: brightness(1.5); } — the second box is half as bright again, so its colour looks washed towards white.
  • .gray { filter: grayscale(100%); } — the third box loses all colour and becomes pure black-and-white.
  • .sepia { filter: sepia(80%); } — the fourth box turns warm and brownish, like an old photograph.
  • .portrait:hover { filter: grayscale(0%); } — the big box starts black-and-white and returns to full colour when you hover over it in a browser.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Photo Filters in CSS</title>
<style>
* { box-sizing: border-box; }
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f2f2f2; }
h1 { text-align: center; color: #333; }
.row { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; max-width: 900px; margin: auto; }
.photo {
  width: 200px; height: 140px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px; font-weight: bold;
  background-color: #ff9800;
}
.blur { filter: blur(3px); }
.bright { filter: brightness(1.5); background-color: #e91e63; }
.gray { filter: grayscale(100%); background-color: #2196f3; }
.sepia { filter: sepia(80%); background-color: #04aa6d; }
.contrast { filter: contrast(150%); background-color: #9c27b0; }
.portrait {
  width: 260px; height: 160px; margin: 30px auto; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 20px; font-weight: bold;
  background-color: #2196f3;
  filter: grayscale(100%);
}
.portrait:hover { filter: grayscale(0%); }
p.note { text-align: center; color: #666; max-width: 600px; margin: 20px auto; }
</style>
</head>
<body>

<h1>One Line, A New Mood</h1>

<div class="row">
<div class="photo blur">Blur</div>
<div class="photo bright">Bright</div>
<div class="photo gray">Grayscale</div>
<div class="photo sepia">Sepia</div>
<div class="photo contrast">Contrast</div>
</div>

<div class="portrait">Hover over me</div>

<p class="note">Each box shows a colour with a different filter. The last box is black-and-white until you hover over it in a browser — then its colour returns.</p>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Filters Tutorial — Blur, Grayscale, Sepia & More

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What does the filter property do?

It applies a visual effect to a whole element — an image, a box, even a block of text — changing its pixels, not its size or position.

2. What do grayscale and sepia do?

grayscale() removes colour for a black-and-white look, and sepia() gives a photo a warm, old look.

3. Can a child undo its parent's filter?

No. A parent's filter covers all its children, and a child cannot escape it.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

AI Power Skills in 2 Days | Learn AI Text, Image, Video and Voice Tools
View
Core Python Programming – 3 Month Complete Course
₹700
View
CapCut Mobile Video Editing Course Beginner to Advance
₹99
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🛡️ 7-Day Money-Back Guarantee
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Download karne ke liye login karo. Login ke baad yahi page pe rahoge!

Naya ho? Register karo →