Skip to content

Latest commit

 

History

History
1090 lines (1009 loc) · 34.9 KB

File metadata and controls

1090 lines (1009 loc) · 34.9 KB
title Tailwind CSS Icon Button for React - Material Tailwind
description Customise your web projects with our easy-to-use icon button component for Tailwind CSS and React using Material Design guidelines.
navigation
icon-button
icon-button-variants
icon-button-sizes
icon-button-colors
icon-button-rounded
icon-button-with-link
icon-button-ripple-effect
icon-button-with-custom-styles
font-awesome-cdn-link
icon-button-props
types-variant
types-size
types-color
icon-button-theme
icon-button-theme-object-type
icon-button-theme-customization
more-examples
github icon-button
prev drawer
next input
# Tailwind CSS Icon Button - React

Use this example to create user-friendly buttons with icon for your Tailwind CSS and React project.


<CodePreview id="icon-button" link="icon-button#icon-button" component={<IconButtonExamples.IconButtonDefault />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonDefault() {
  return (
    <IconButton>
      <i className="fas fa-heart" />
    </IconButton>
  );
}

## Icon Button Variants

The IconButton component comes with 4 different variants that you can change it using the variant prop.

<CodePreview link="icon-button#icon-button-variants" component={<IconButtonExamples.IconButtonVariants />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonVariants() {
  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>
  );
}

## Icon Button Sizes

The IconButton component comes with 3 different sizes that you can change it using the size prop.

<CodePreview link="icon-button#icon-button-sizes" component={<IconButtonExamples.IconButtonSizes />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonSizes() {
  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>
  );
}

## Icon Button Colors

The IconButton component comes with 19 different colors that you can change it using the color prop.

<CodePreview link="icon-button#icon-button-colors" component={<IconButtonExamples.IconButtonColors />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonColors() {
  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>
  );
}

## Icon Button Rounded

You can use tailwind css rounded-full class with IconButton to create rounded icon buttons.

<CodePreview component={<IconButtonExamples.IconButtonRounded />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonRounded() {
  return (
    <div className="flex items-center gap-4">
      <IconButton className="rounded-full">
        <i className="fas fa-heart" />
      </IconButton>
      <IconButton variant="gradient" className="rounded-full">
        <i className="fas fa-heart" />
      </IconButton>
      <IconButton variant="outlined" className="rounded-full">
        <i className="fas fa-heart" />
      </IconButton>
      <IconButton variant="text" className="rounded-full">
        <i className="fas fa-heart" />
      </IconButton>
    </div>
  );
}

## Icon Button with Link

You can wrap IconButton component with {<a>} tag to make it a link.

<CodePreview component={<IconButtonExamples.IconButtonWithLink />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonWithLink() {
  return (
    <div className="flex items-center gap-4">
      <a href="#buttons-with-link">
        <IconButton>
          <i className="fas fa-heart" />
        </IconButton>
      </a>
      <a href="#buttons-with-link">
        <IconButton variant="gradient">
          <i className="fas fa-heart" />
        </IconButton>
      </a>
      <a href="#buttons-with-link">
        <IconButton variant="outlined">
          <i className="fas fa-heart" />
        </IconButton>
      </a>
      <a href="#buttons-with-link">
        <IconButton variant="text">
          <i className="fas fa-heart" />
        </IconButton>
      </a>
    </div>
  );
}

## Icon Button Ripple Effect

You can turn on/off the ripple effect for the IconButton component using the ripple prop.

<CodePreview link="icon-button#icon-button-ripple-effect" component={<IconButtonExamples.IconButtonRippleEffect />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonRippleEffect() {
  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>
  );
}

## Icon Button with Custom Styles

You can use the className prop to add custom styles to the IconButton component.

<CodePreview component={<IconButtonExamples.IconButtonCustomStyles />}>

import { IconButton } from "@material-tailwind/react";

export function IconButtonCustomStyles() {
  return (
    <div className="flex gap-4">
      <IconButton className="rounded bg-[#ea4335] hover:shadow-[#ea4335]/20 focus:shadow-[#ea4335]/20 active:shadow-[#ea4335]/10">
        <i className="fab fa-google text-lg" />
      </IconButton>
      <IconButton className="rounded bg-[#1DA1F2] hover:shadow-[#1DA1F2]/20 focus:shadow-[#1DA1F2]/20 active:shadow-[#1DA1F2]/10">
        <i className="fab fa-twitter text-lg" />
      </IconButton>
      <IconButton className="rounded bg-[#ea4c89] hover:shadow-[#ea4c89]/20 focus:shadow-[#ea4c89]/20 active:shadow-[#ea4c89]/10">
        <i className="fab fa-dribbble text-lg" />
      </IconButton>
      <IconButton className="rounded bg-[#333333] hover:shadow-[#333333]/20 focus:shadow-[#333333]/20 active:shadow-[#333333]/10">
        <i className="fab fa-github text-lg" />
      </IconButton>
    </div>
  );
}

## Font Awesome CDN Link

In case of using icon fonts rather than svg icons please add their cdn links to your project, if you're using font awesome you can use the below cdn link.