Use this example to create user-friendly buttons with icon for your Tailwind CSS and React project.
import { IconButton } from "@material-tailwind/react";
export default function Example() {
return (
<IconButton>
<i className="fas fa-heart" />
</IconButton>
);
}
The IconButton
component comes with 4 different variants that you can change it using the variant
prop.
import { IconButton } from "@material-tailwind/react";
export default function Variants() {
return (
<div className="flex gap-4">
<IconButton>
<i className="fas fa-heart" />
</IconButton>
<IconButton variant="gradient">
<i className="fas fa-heart" />
</IconButton>
<IconButton variant="outlined">
<i className="fas fa-heart" />
</IconButton>
<IconButton variant="text">
<i className="fas fa-heart" />
</IconButton>
</div>
);
}
The IconButton
component comes with 3 different sizes that you can change it using the size
prop.
import { IconButton } from "@material-tailwind/react";
export default function Sizes() {
return (
<div className="flex items-end gap-4">
<IconButton size="sm">
<i className="fas fa-heart" />
</IconButton>
<IconButton size="md">
<i className="fas fa-heart" />
</IconButton>
<IconButton size="lg">
<i className="fas fa-heart fa-lg" />
</IconButton>
</div>
);
}
The IconButton
component comes with 19 different colors that you can change it using the color
prop, below there are some examples of the colors but you can check all of the them here.
import { IconButton } from "@material-tailwind/react";
export default function Colors() {
return (
<div className="flex gap-4">
<IconButton color="blue">
<i className="fas fa-heart" />
</IconButton>
<IconButton color="red">
<i className="fas fa-heart" />
</IconButton>
<IconButton color="green">
<i className="fas fa-heart" />
</IconButton>
<IconButton color="amber">
<i className="fas fa-heart" />
</IconButton>
</div>
);
}
You can turn on/off the ripple effect for the IconButton
component using the ripple
prop.
import { IconButton } from "@material-tailwind/react";
export default function Example() {
return (
<div className="flex w-max gap-4">
<IconButton ripple={true}>
<i className="fas fa-heart" />
</IconButton>
<IconButton ripple={false}>
<i className="fas fa-heart" />
</IconButton>
</div>
);
}