Navigated to /docs/ui/components/aspect-ratio

AspectRatio

Fixed-ratio media and content frame primitive.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import the component from its dedicated entry point to keep the dependency and generated bundle explicit.

TSX
tsximport { AspectRatio } from "@tavojs/ui/aspect-ratio";

Normal Tavo.js applications load component styles through the Tavo.js UI plugin. If the application manages component CSS manually, also import @tavojs/ui/css/aspect-ratio.

When to use

Use it when

Use `AspectRatio` for media, previews, embeds, and thumbnails that need stable dimensions

Choose something else when

Avoid AspectRatio when for interactive form state; combine with form, feedback, or data components instead.

Examples

AspectRatio example

TSX
tsximport { AspectRatio } from "@tavojs/ui/aspect-ratio";

export function AspectRatioExample1() {
  return (
    <>
      <AspectRatio ratio={{ base: "1/1", md: "16/9" }}>
        <img src="/cover.jpg" alt="Product preview" />
      </AspectRatio>
    </>
  );
}

Common props and defaults

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
ratioResponsiveValue<number | "\${number}/\${number}">

Configures ratio for this component.

Complete TypeScript API

Import from @tavojs/ui/aspect-ratio. Published exports: AspectRatio, AspectRatioProps.

AspectRatioProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by AspectRatio.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by AspectRatio.

idstring

No

Inherited id attribute accepted by AspectRatio.

rolestring

No

Inherited role attribute accepted by AspectRatio.

styleRecord<string, unknown>

No

Inherited style attribute accepted by AspectRatio.

titlestring

No

Inherited title attribute accepted by AspectRatio.

tabIndexnumber

No

Inherited tabIndex attribute accepted by AspectRatio.

hiddenboolean

No

Inherited hidden attribute accepted by AspectRatio.

disabledboolean

No

Inherited disabled attribute accepted by AspectRatio.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by AspectRatio.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by AspectRatio.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by AspectRatio.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by AspectRatio.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by AspectRatio.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by AspectRatio.

ratioResponsiveValue<Ratio>

No

Configures ratio for this component.

State ownership and DOM target

ConcernContract
StateNo component state contract is exposed; the application owns the rendered content and surrounding behavior.
DOM targetPublic passthrough props target the component root. Treat nested elements and private class names as implementation details.

Anatomy and related components

This component exposes one public component root rather than a compound member API.

Limitations

Avoid AspectRatio when for interactive form state; combine with form, feedback, or data components instead.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

The wrapper is semantic-neutral; keep accessible labels on the media or content inside.

  • The wrapper is semantic-neutral; keep accessible labels on the media or content inside.

Component status

ContractCurrent value
Maturitystable
Categorylayout
Component import@tavojs/ui/aspect-ratio
Explicit CSS import@tavojs/ui/css/aspect-ratio
PreviewInteractive preview available on this page