How to use tailwindcss with nextjs image
See original GitHub issueBug report
Describe the bug
Hello, I am trying to use tailwindcss in Nextjs project. But I can’t use my tailwind classes with Nextjs image component. Here’s my code.
To Reproduce
<Image
src={img.img}
alt="Picture of the author"
width="200"
height="200"
className="h-56 w-56 object-cover"
></Image>
Expected behavior
Here I want to use tailwind classes instead of the height and width property of the nextjs image. But I can’t because it throws me an error. Also, unsized property throws another error saying it’s deprecated. Is there any solution? thanks in advance.
Here is the error if I don’t use height and width property.
When I use layout = ‘fill’ property it shows only one picture. And if I use unsized property, then the following error is shown.
The problem here is that I always have to use height and width but I can’t make it to work with tailwindcss classes
Screenshots
System information
- OS: Windows
- Browser: chrome, safari
- Version of Next.js: 10.0.1
- Version of Node.js: e.g. 14.0.0
- Deployment: I still haven’t deployed yet
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to use Tailwind CSS with Next.js Image - Stack Overflow
I want to use Tailwind classes instead of the height and width property of the Next.js Image. But I can't because it throws...
Read more >How to use Tailwind CSS with Next.js - DEV Community
Hello guys, hope you are doing well. In this post I am going to discuss how to properly use tailwindcss classes with next.js....
Read more >How to use next/future/image with Tailwind CSS? #38945
Next.js Image is extremely difficult to work with. Either the old one or the new one. It's our entire team's opinion. However, because...
Read more >Install Tailwind CSS with Next.js
The quickest way to start using Tailwind CSS in your Next.js project is to use the Next.js + Tailwind CSS Example. This will...
Read more >Building an Image Gallery with Next.js, Supabase, and ...
To set up your application, we can use create-next-app to clone a Next.js and Tailwind CSS starter application from the official examples ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This only solves things when the width and height are fixed. The Image component completely ignores every tailwind class. For example
With classes: className=“order-first lg:order-last mb-8 lg:mb-0 max-h-96 max-w-3/4 mx-auto”
Gets transformed into this:
Setting up random width - height does not fix it, classes: "order-first lg:order-last max-h-96 max-w-3/4 are just being completely ignored.
Having the image under a div with those classes does not work neither.
that’s because you are using layout=‘fill’. Just delete that and use height and width instead. Here’s my working code.