Examples

Ratios

Preview

1.00

1.33

1.78

Example.tsx
import { AspectRatio, Center, SimpleGrid, Text } from '@reactloom/ui';

export default function Example() {
  return (
    <SimpleGrid columns={{ base: 1, sm: 3 }} gap="4" style={{ width: '100%' }}>
      {[1, 4 / 3, 16 / 9].map((ratio) => (
        <AspectRatio key={ratio} ratio={ratio}>
          <Center style={{ background: 'var(--pl-color-accent-subtle)', borderRadius: 8 }}>
            <Text tone="accent" weight="semibold">{ratio.toFixed(2)}</Text>
          </Center>
        </AspectRatio>
      ))}
    </SimpleGrid>
  );
}

API reference

AspectRatio props
PropTypeDefault
ratio
width / height, e.g. 16 / 9.
number1

Accessibility

  • Give images alt text and iframes a title.

Usage guidelines

Do

  • Reserve space for media to avoid layout shift.

Don’t