Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-aspect-ratio

Package Overview
Dependencies
Maintainers
6
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-aspect-ratio

  • 1.1.0-rc.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is @radix-ui/react-aspect-ratio?

@radix-ui/react-aspect-ratio is a React component library that provides a way to maintain a consistent aspect ratio for an element. This is particularly useful for responsive design, ensuring that elements like images, videos, and other media maintain their proportions across different screen sizes.

What are @radix-ui/react-aspect-ratio's main functionalities?

Basic Aspect Ratio

This feature allows you to wrap any element with the AspectRatio component to maintain a 16:9 aspect ratio. The child element will scale to fit the specified ratio.

import { AspectRatio } from '@radix-ui/react-aspect-ratio';

function App() {
  return (
    <AspectRatio ratio={16 / 9}>
      <img src="https://via.placeholder.com/800x450" alt="Example" />
    </AspectRatio>
  );
}

Custom Aspect Ratio

This feature allows you to specify a custom aspect ratio, such as 4:3, for any element. The child element will adjust its size to maintain the specified ratio.

import { AspectRatio } from '@radix-ui/react-aspect-ratio';

function App() {
  return (
    <AspectRatio ratio={4 / 3}>
      <div style={{ background: 'lightblue', width: '100%', height: '100%' }}>Custom Aspect Ratio</div>
    </AspectRatio>
  );
}

Responsive Aspect Ratio

This feature demonstrates how the AspectRatio component can be used within a responsive container. The aspect ratio is maintained even as the container resizes.

import { AspectRatio } from '@radix-ui/react-aspect-ratio';

function App() {
  return (
    <div style={{ width: '50%' }}>
      <AspectRatio ratio={1}>
        <div style={{ background: 'lightcoral', width: '100%', height: '100%' }}>Responsive Aspect Ratio</div>
      </AspectRatio>
    </div>
  );
}

Other packages similar to @radix-ui/react-aspect-ratio

FAQs

Package last updated on 11 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc