Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Styling Section to next/image component docs #28055

Merged
merged 6 commits into from Aug 14, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api-reference/next/image.md
Expand Up @@ -263,6 +263,14 @@ Other properties on the `<Image />` component will be passed to the underlying
- `ref`. Use [`onLoadingComplete`](#onloadingcomplete) instead.
- `decoding`. It is always `"async"`.

## Styling

`next/image` wraps the `img` component with containers to maintain the aspect ratio of the image and prevent [Cumulative Layout Shift](https://vercel.com/blog/core-web-vitals#cumulative-layout-shift).
leerob marked this conversation as resolved.
Show resolved Hide resolved

To add styles to the underlying `img` element, pass the `className` prop to the `<Image />` component. Then, use Next.js' [built-in CSS support](/docs/basic-features/built-in-css-support.md) to add rules to that class.

**Note:** If using [`layout="fill"`](/docs/api-reference/next/image.md#layout), ensure the parent element has `position: relative` in their stylesheet.
leerob marked this conversation as resolved.
Show resolved Hide resolved

## Related

For more information on what to do next, we recommend the following sections:
Expand Down