Skip to content

Object Fit

Control how media content fits its container

Syntax

layout="object:[value]"

Values

ValueCSS OutputDescription
containobject-fit: containScale to fit, preserve ratio
coverobject-fit: coverCover container, may crop
fillobject-fit: fillStretch to fill
noneobject-fit: noneNo scaling
scale-downobject-fit: scale-downSmaller of none or contain

Examples

html
<img layout="object:cover">Cover image</img>

Preview

Object Fit Cover

layout="object:cover" - Image covers container, may crop

object:cover
View Code
html
<div layout="flex" space="g:small p:medium" visual="bg:neutral-100 dark:bg:neutral-900 rounded:medium">
  <div style="width: 80px; height: 60px;" visual="bg:neutral-300 rounded:small" layout="overflow:hidden">
    <div layout="object:cover" style="width: 100%; height: 100%;" visual="bg:primary"></div>
  </div>
  <span layout="flex center" visual="text:neutral-600 dark:text:neutral-400">object:cover</span>
</div>

Object Fit Contain

layout="object:contain" - Image fits inside, preserves ratio

object:contain
View Code
html
<div layout="flex" space="g:small p:medium" visual="bg:neutral-100 dark:bg:neutral-900 rounded:medium">
  <div style="width: 80px; height: 60px;" visual="bg:neutral-300 rounded:small" layout="flex center">
    <div layout="object:contain" style="width: 60%; height: 60%;" visual="bg:primary rounded:small"></div>
  </div>
  <span layout="flex center" visual="text:neutral-600 dark:text:neutral-400">object:contain</span>
</div>