# object-fit-images
> Polyfill `object-fit` and `object-position` on images on IE9, IE10, IE11, Edge, Safari, ...
[![gzipped size](https://badges.herokuapp.com/size/github/bfred-it/object-fit-images/master/dist/ofi.min.js?gzip=true&label=gzipped%20size)](#readme) [![Travis build status](https://api.travis-ci.org/bfred-it/object-fit-images.svg)](https://travis-ci.org/bfred-it/object-fit-images) [![npm version](https://img.shields.io/npm/v/object-fit-images.svg)](https://www.npmjs.com/package/object-fit-images)
This adds support for `object-fit` and `object-position` to **IEdge 9-13, Android < 5, Safari < 10** and skips browsers that already support them.
Take a look at the [demo.](http://bfred-it.github.io/object-fit-images/demo/)
## Main features
- Fast and lightweight
- No additional elements are created or necessary
- Once set, position is taken care by the browser
- `srcset` support
- You can still access/change `src` and `srcset` properties and attributes: `img.src = 'other-image.jpg'`
## Comparison table with alternative solutions
### Support
| bfred-it
/object-fit-images🌟 | [constancecchen
/object-fit-polyfill](https://github.com/constancecchen/object-fit-polyfill) | [tonipinel
/object-fit-polyfill](https://github.com/tonipinel/object-fit-polyfill) | [jonathantneal
/fitie](https://github.com/jonathantneal/fitie)
:--- | :--- | :--- | :--- | :---
Browsers | IEdge 9-14, Android<5, Safari<10 | <- Same | "All browsers" | IE 8-11
Tags | `img` | `image` `video` `picture` | `img` | `img` `video`
`cover/contain` | 💚 | 💚 | 💚 | 💚
`fill` | 💚 | 💚 | 💚 | 💚
`none` | 💚 | 💚 | 💚 | 💔
`scale-down` | 💚 using [`{watchMQ:true}`](#apply-on-resize) | 💚 | 💔 | 💔
`object-position` | 💚 | 💚 | 💔 | 💔
`srcset` support | 💚 Native or [picturefill](https://github.com/scottjehl/picturefill) [notes](detailed-support-tables.md) | 💚 | 💔 | 💔
Extra elements | 💚 No | 💔 Yes | 💔 Yes | 💔 Yes
Settings | 💚 via CSS | 💔 via HTML | 💔 via HTML | 💔 via HTML
## Usage
You will need 3 things
0. one or more `` elements with `src` or `srcset`
```html
```
0. CSS defining `object-fit` and a special `font-family` property to allow IE to read the correct value
```css
.your-favorite-image {
object-fit: contain;
font-family: 'object-fit: contain;'
}
```
or, if you also need `object-position`
```css
.your-favorite-image {
object-fit: cover;
object-position: bottom;
font-family: 'object-fit: cover; object-position: bottom;'
}
```
To generate the `font-family` automatically, you can use the [PostCSS plugin](https://github.com/ronik-design/postcss-object-fit-images) or the [SCSS/SASS/Less mixins.](/preprocessors)
If you set the `font-family` via javascript (which must be followed by calling `objectFitImages()`), make sure to include the quotes [**in** the property.](https://github.com/bfred-it/object-fit-images/issues/29#issuecomment-227491892)
0. the activation call before `