1. Components
  2. aspect-ratio

Aspect Ratio

Utility component to maintain specific dimensions for images or videos.

Demo

Image by Johnnathan Tshibangu
<x-ui.aspect aspect="video">
    <img src="/images/img2.webp" class="w-full h-full object-cover rounded-lg" width="2400"
        alt="Image by Johnnathan Tshibangu">
</x-ui.aspect>

Installation

Shell
flexi-cli add aspect

Examples

Square

Image by Johnnathan Tshibangu
<x-ui.aspect aspect="square">
    <img src="/images/img2.webp" class="w-full h-full object-cover rounded-lg" width="2400"
        alt="Image by Johnnathan Tshibangu">
</x-ui.aspect>

Video

Image by Johnnathan Tshibangu
<x-ui.aspect aspect="video">
    <img src="/images/img2.webp" class="w-full h-full object-cover rounded-lg" width="2400"
        alt="Image by Johnnathan Tshibangu">
</x-ui.aspect>

Standard TV

Image by Johnnathan Tshibangu
<x-ui.aspect aspect="standard-tv">
    <img src="/images/img2.webp" class="w-full h-full object-cover rounded-lg" width="2400"
        alt="Image by Johnnathan Tshibangu">
</x-ui.aspect>

35mm film

Image by Johnnathan Tshibangu
<x-ui.aspect aspect="35mm-film">
    <img src="/images/img2.webp" class="w-full h-full object-cover rounded-lg" width="2400"
        alt="Image by Johnnathan Tshibangu">
</x-ui.aspect>

Ultra wide

Image by Johnnathan Tshibangu
<x-ui.aspect aspect="ultrawide">
    <img src="/images/img2.webp" class="w-full h-full object-cover rounded-lg" width="2400"
        alt="Image by Johnnathan Tshibangu">
</x-ui.aspect>

References

Props

The aspect ratio component accepts the following props. The aspect prop is required.

Prop Type Default Description
aspect string 'video'
The aspect ratio of the container. Can be one of the predefined values or a custom aspect ratio class.

Predefined values:
  • video - 16:9 aspect ratio
  • square - 1:1 aspect ratio
  • 35mm-film - 3:2 aspect ratio
  • standard-tv - 4:3 aspect ratio
  • ultrawide - 21:9 aspect ratio
class string ''
Additional CSS classes to apply to the aspect ratio container.