Aspect Ratio
Constrains its content to a given width/height ratio.
Preview
<x-ui.aspect-ratio ratio="16 / 9" class="rounded-lg border border-border">
<div class="flex h-full w-full items-center justify-center bg-muted text-muted-foreground">{{ __('16 / 9') }}</div>
</x-ui.aspect-ratio>
Installation
php artisan ui:add aspect-ratio
Registry contract
php artisan ui:add aspect-ratio
writes only the files below. The CLI validates each file hash before writing and asks before it replaces a local change, unless you pass --force.
-
resources/views/components/ui/aspect-ratio.blade.php
- Registry dependencies
- None — installs on its own.
- Packages
-
composer: jml/brok:^0.2
Use with AI
A brief for your coding agent: install command, usage, props, guidance and the rules. Copy it, or open a prompt about this component in an assistant.
# Brok UI: Aspect Ratio (`aspect-ratio`)
Constrains its content to a given width/height ratio.
Brok UI is a Laravel Blade component registry. Installed components are plain Blade files the app owns.
## Install
```bash
php artisan ui:add aspect-ratio
```
## Usage
```blade
<x-ui.aspect-ratio ratio="16 / 9" class="rounded-lg border border-border">
<div class="flex h-full w-full items-center justify-center bg-muted text-muted-foreground">{{ __('16 / 9') }}</div>
</x-ui.aspect-ratio>
```
## Props
- `ratio` (string, default `16 / 9`) — CSS aspect-ratio value, such as "16 / 9" or "1 / 1".
## Use when
- Use to structure hierarchy, spacing, and responsiveness so content is easier to scan and navigate.
- Reserving stable space for media (images, video, embeds) before it loads, to prevent layout shift.
- Constraining a flexible-width container to a fixed width/height ratio, such as 16/9 or 1/1.
## Avoid when
- Do not let layout primitives substitute for semantics, headings, or interaction rules users still need.
- The content already has intrinsic dimensions and layout shift is not a concern; a plain width/height suffices.
- The content needs to scroll within a fixed viewport rather than scale to a ratio; use scroll-area.
## Anti-patterns
- Using visual layout as a substitute for semantic structure
## Rules
- Use the `<brok:aspect-ratio>` tag (or `<x-ui.aspect-ratio>`) in Blade; do not rewrite the component.
- Prefer the documented props and variants over utility-class overrides; when a utility must win, use the `!` important modifier.
- Use semantic design tokens (`bg-primary`, `text-muted-foreground`), never raw colour utilities.
- Keep the `data-slot` attributes; they are the styling and test hooks.
## Links
- Docs: https://brokui.dev/docs/components/aspect-ratio
- Registry JSON (files, props, contract): https://brokui.dev/r/open/aspect-ratio.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| ratio | string | 16 / 9 | CSS aspect-ratio value, such as "16 / 9" or "1 / 1". |
Slots
default— Content stretched to fill the constrained box, typically an image or iframe with h-full w-full object-cover.
Data slots
Stable hooks for CSS overrides and browser tests.
Behavior
- Sets the CSS aspect-ratio property directly via an inline style, so the ratio applies before any child content loads.
- The root clips overflowing content, so child media should be sized to fill it (for example object-cover).
- Declares registry capability flags: a11y, responsive, rtl, darkMode, localized.
Guidance
Structure content hierarchy and responsive relationships.
Use when
- Use to structure hierarchy, spacing, and responsiveness so content is easier to scan and navigate.
- Reserving stable space for media (images, video, embeds) before it loads, to prevent layout shift.
- Constraining a flexible-width container to a fixed width/height ratio, such as 16/9 or 1/1.
Avoid when
- Do not let layout primitives substitute for semantics, headings, or interaction rules users still need.
- The content already has intrinsic dimensions and layout shift is not a concern; a plain width/height suffices.
- The content needs to scroll within a fixed viewport rather than scale to a ratio; use scroll-area.
Use instead
- Semantic HTML with standard flow
Anti-patterns
- Using visual layout as a substitute for semantic structure
- Anatomy
- Theming hooks
Accessibility
- Keyboard
- No component-owned keyboard interaction; native element behavior applies.
- Focus
none
- The wrapper is purely presentational; accessible names and descriptions belong on the slotted content itself, such as an image's alt text.
- Semantic HTML and a stable
data-slotattribute for styling and scripting hooks. - Focus-visible rings use the
ringtoken, so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces in the preview.
- Labels go through
__()and layout uses logical properties (ms-*,text-start), so it mirrors underdir="rtl"— flip the preview to RTL to confirm. - Dark mode uses the same semantic tokens under the
darkclass; high contrast follows forced-color system tokens.
Livewire
Livewire can update this component through forwarded wire:* attributes.
Source
The exact, editable file ui:add writes
into your app. Previews render this same code; there are no preview-only components.
@props(['ratio' => '16 / 9'])
<div data-slot="aspect-ratio" style="aspect-ratio: {{ $ratio }};" {{ $attributes->merge(['class' => 'relative w-full overflow-hidden']) }}>
{{ $slot }}
</div>
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.0.3 - Status
- Stable
- License
-
open - Accessibility reviewed
- No review date recorded
- Last breaking change
- No date recorded
- Deprecation
- Not deprecated
- Contract
-
v6 - Foundation
-
≥ 1.0.0