The clip property

The clip property allows cropping an absolutely positioned element, leaving only the specified rectangular area visible. The value is specified using the rect function.

Syntax

cssselector {
  clip: rect(top, right, bottom, left) | auto;
}

Preparing images

Let's take a nature image that we'll be cropping:

html<img src="image.jpg" width="500">

Результат:

Example

Let's crop the image, leaving only the central part visible:

html<div class="container">
  <img class="image" src="image.jpg">
</div>
css.container {
  position: relative;
  width: 400px;
  height: 300px;
}
.image {
  position: absolute;
  clip: rect(50px, 350px, 250px, 50px);
  width: 400px;
  height: 300px;
}

Результат:

See also

  • the clip-path property,
    a modern alternative for cropping elements
  • the mask property,
    which allows applying a mask
  • the position property,
    required for clip to work
  • the overflow property,
    which can also hide parts of content