Concepts
OverviewCompositionTestingLayout
Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrapComponents
AccordionAdmonitionAvatarButtonCheckboxComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsProgressPrompt ModalRadioRatingSelectSwitchTableTabsTagTextTextareaToggleTooltipUtilities
Feature FlagsForLocal StoragePortalShowsplitPropsThemeUsage
1import { AspectRatio } from "styled-system/jsx";
1<AspectRatio>2 <iframe3 title="naruto"4 src="https://www.youtube.com/embed/QhBnZ6NPOY0"5 allowFullScreen6 />7</AspectRatio>
Examples
Image
Here's how to embed an image that has a 4 by 3 aspect ratio.
1import { AspectRatio } from "styled-system/jsx";2
3const Demo = () => {4 return (5 <AspectRatio maxW="400px" ratio={4 / 3}>6 <img src="https://bit.ly/naruto-sage" alt="naruto" />7 </AspectRatio>8 )9}
Video
To embed a video with a specific aspect ratio, use an iframe with src
pointing
to the link of the video.
1import { AspectRatio } from "styled-system/jsx";2
3const Demo = () => {4 return (5 <AspectRatio maxW="560px" ratio={1}>6 <iframe7 title="naruto"8 src="https://www.youtube.com/embed/QhBnZ6NPOY0"9 allowFullScreen10 />11 </AspectRatio>12 )13}
Google Map
Here's how to embed a responsive Google map using AspectRatio
.
1import { AspectRatio } from "styled-system/jsx";2
3const Demo = () => {4 return (5 <AspectRatio ratio={16 / 9}>6 <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3963.952912260219!2d3.375295414770757!3d6.5276316452784755!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x103b8b2ae68280c1%3A0xdc9e87a367c3d9cb!2sLagos!5e0!3m2!1sen!2sng!4v1567723392506!5m2!1sen!2sng" />7 </AspectRatio>8 )9}
Responsive
Here's an example of applying a responsive aspect ratio to a box.
1import { AspectRatio } from "styled-system/jsx"2import { DecorativeBox } from "compositions/lib/decorative-box"3
4export const AspectRatioResponsive = () => (5 <AspectRatio maxWidth="300px" ratio={{ base: 1, md: 16 / 9 }}>6 <DecorativeBox>Box</DecorativeBox>7 </AspectRatio>8)
Props
These props can be passed to the AspectRatio
component.
Prop | Type | Description |
---|---|---|
ratio | ConditionalValue<number> | The aspect ratio of the Box. Common values are: 21/9 , 16/9 , 9/16 , 4/3 , 1.85/1 |
On this page