--- title: "aspect-ratio" description: "Holds its children to a fixed width-to-height ratio." category: "Layout" --- # aspect-ratio Holds its children to a fixed width-to-height ratio. ## Installation ```bash php artisan ui:add aspect-ratio ``` ## Dependencies - composer: `gehrisandro/tailwind-merge-laravel` ## Usage ```blade ``` ## Example The demo rendered on the docs page. ```blade
16 / 9
``` ## Source Copy this file to the path shown above it. `resources/views/components/ui/aspect-ratio.blade.php` ```blade @props([ 'ratio' => '16/9', ]) @php $classes = \TailwindMerge\Laravel\Facades\TailwindMerge::merge( 'relative w-full', $attributes->get('class'), ); @endphp {{-- The ratio is an inline style on purpose. aspect-[{{ '$ratio' }}] would be built from a runtime value, and Tailwind only compiles classes it can find by scanning source files, so that class would never exist. --}}
except('class')->merge(['class' => $classes]) }}> {{ $slot }}
``` ## Theme tokens No JavaScript and no tokens. Pass `ratio` as any CSS aspect-ratio value ("16/9", "1/1", "1.85"). Give the child `size-full object-cover` to fill the box.