CSS object-fit Property Values



The object-fit property in CSS is used to resize image or video to fit its container. It has the following values

  • contain: Content is scaled to fit
  • cover: clipped to fit
  • fill: fills the content box.

Example

You can try to run the following code to implement object-fit property with the cover value.

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         .myimg {
            width:250px;
            height:350px;
            object-fit:fill;
         }
      </style>
   </head>
   <body>
      <h2>SWIFT</h2>
      <img class = "myimg"
         src = "https://www.tutorialspoint.com/assets/videos/courses/67/images/course_67_image.png"
         alt = "Python Data Science" width = "300" height = "200">
   </body>
</html>
Updated on: 2020-07-03T07:37:12+05:30

119 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements