⟦Škíp tó çóñtéñt~~~~~~⟧
uiify

Aspect Ratio

⟦Á médíá frámé thát préšérvéš ítš wídth-tó-héíght rátíó.~~~~~~~~~~~~~~~~~~~~⟧

⟦Brówšérš~~~⟧
Chrome 123+Firefox 121+Safari 17.5+
⟦Tíér~~⟧
0
⟦Búñdlé çómpréššéd~~~~~~⟧
268 B
⟦Fórçéd láýóút búdgét~~~~~~~⟧
0 ms
⟦Áxé búdgét~~~~⟧
0
⟦ŠŠR çómpátíblé~~~~~⟧
⟦Ýéš~~⟧
⟦Públíšhéd çóñtráçt~~~~~~~⟧
⟦Téšt hárñéšš~~~~~⟧

⟦Pláýgróúñd~~~~⟧

16:9 · Cover

An amber sun above overlapping blue mountain ridges

⟦Éxámpléš~~~⟧

Square

The default ratio is 1. A square frame crops a landscape image at the sides.

An amber sun above overlapping blue mountain ridges
import { AspectRatio } from "@gunkin/uiify";

<AspectRatio>
  <img src="/mountains.svg" width="640" height="400" alt="An amber sun above blue mountain ridges" />
</AspectRatio>

Portrait

Set ratio to 4 / 5 for a portrait frame. The image keeps its proportions while filling the frame.

An amber sun above overlapping blue mountain ridges
import { AspectRatio } from "@gunkin/uiify";

<AspectRatio ratio={4 / 5}>
  <img src="/mountains.svg" width="640" height="400" alt="An amber sun above blue mountain ridges" />
</AspectRatio>

Contain

Apply .uncropped { object-fit: contain; } to keep the whole image visible. The optional skin supplies the frame background.

An amber sun above overlapping blue mountain ridges
import { AspectRatio } from "@gunkin/uiify";

<AspectRatio ratio={16 / 9}>
  <img className="uncropped" src="/mountains.svg" width="640" height="400" alt="An amber sun above blue mountain ridges" />
</AspectRatio>

⟦ÁPÍ~~⟧

AspectRatio

⟦Próp~~⟧⟦Týpé~~⟧⟦Défáúlt~~~⟧⟦Déšçríptíóñ~~~~⟧
rationumber1⟦Póšítívé fíñíté wídth dívídéd bý héíght. Íñválíd ñúmbérš fáll báçk tó 1. Whéñ ómíttéd, thé ÇŠŠ çúštóm própértý çáñ šét thé rátíó.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧
childrenReactNode—⟦Çóñtéñt pláçéd íñšídé thé frámé. Íñtríñšíç çóñtéñt çáññót éñlárgé thé frámé.~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧
classNamestring—⟦Çlášš ápplíéd tó thé frámé róót.~~~~~~~~~~~~⟧
styleCSSProperties—⟦Ñátívé róót štýléš, íñçlúdíñg --úíífý-ášpéçt-rátíó whéñ rátíó íš ómíttéd.~~~~~~~~~~~~~~~~~~~~~~~~~~⟧
refRef<HTMLElement>—⟦Réf fórwárdéd tó thé réñdéréd róót éléméñt.~~~~~~~~~~~~~~~~⟧
asElementType"div"⟦Ñátívé éléméñt ór çómpóñéñt úšéd fór thé róót.~~~~~~~~~~~~~~~~~⟧
renderReactElement | ((props, state) => ReactElement)—⟦Répláçé thé réñdéréd róót whílé préšérvíñg ítš própš, réf áñd ídéñtítý márkér.~~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧

⟦Kéýbóárd~~~⟧

⟦Kéý~~⟧⟦Áçtíóñ~~~⟧

⟦Áççéššíbílítý~~~~~⟧

⟦Štátíç láýóút áddš ñó rólé, fóçúš tárgét ór kéýbóárd béhávíór. Gívé méáñíñgfúl ímágéš ált téxt; kéép çáptíóñš óútšídé thé frámé. Réqúíréd béhávíór ÇŠŠ préšérvéš thé rátíó évéñ whéñ çhíldréñ hávé íñtríñšíç díméñšíóñš. Óptíóñál štýléš fíll ímágéš wíth óbjéçt-fít: çóvér; úšé çóñtáíñ tó šhów thé éñtíré ímágé.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧

⟦Štýlíñg hóókš~~~~~⟧

data-uiify-aspect-ratiodata-part="content"--uiify-aspect-ratio