Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

CSS Clip‑Path & Masking | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 32 of 50

·css

CSS Clip‑Path & Masking

7 mins

Course progress64%

What you'll learn

Keep this idea in mind as you work through the lesson.

1 point
  • `clip-path` accepts basic shapes (`circle`, `ellipse`, `polygon`) and can be animated. * `mask-image` works with gradients and images to create complex transparency effects.

clip-path and mask-image let you cut or mask elements into arbitrary shapes.

clip-path

  • Accepts basic shapes (circle(), ellipse(), polygon()) and SVG path syntax (path('…')).
  • Can be animated (e.g., morph from a circle to a square).
  • Does not affect the element’s layout – it only hides the overflow.
.card {
  width:300px; height:200px; background:#0066cc;
  clip-path:polygon(0 0, 100% 0, 85% 100%, 0 85%);
}

mask-image

  • Works like a black‑and‑white layer – white shows, black hides.
  • Supports gradients, images, and SVG files.
  • Often paired with mask-size, mask-position, and mask-repeat.
.avatar {
  width:200px; height:200px; background:url('portrait.jpg') center/cover;
  mask-image:radial-gradient(circle at center, transparent 0%, black 70%);
  mask-size:cover;
}

Animating clip-path

@keyframes morph {
  0%   { clip-path:circle(0% at 50% 50%); }
  100% { clip-path:circle(50% at 50% 50%); }
}
.box { animation:morph 1s forwards ease-out; }

The element reveals itself gradually, useful for onboarding screens.


Browser Compatibility

  • clip-path – supported in all modern browsers; IE needs the older -ms- prefix.
  • mask-image – supported in Chrome, Safari, Edge; Firefox requires the -moz- prefix (and still experimental).

Pro Tip – Use SVG for Complex Shapes

Instead of a long polygon() list, embed an SVG <clipPath> definition and reference it with clip-path:url(#myClip).

Accessibility Reminder

Both properties only affect visual rendering; screen readers still encounter the full element. Use aria-hidden="true" on decorative graphics if they add noise.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonCSS Shapes – Non‑Rectangular LayoutContinue to lesson 33CSS Scroll‑SnapBack to CSS Basics to Advanced curriculum