Tailwind CSS Collapse - React

Use our Tailwind CSS collapse for your website. You can use it for accordion, collapsible items and much more.

See below our simple Collapse example that you can use in your Tailwind CSS and React project.


Use our Tailwind CSS collapse for your website. You can use if for accordion, collapsible items and much more.

import React from "react";
import {
  Collapse,
  Button,
  Card,
  Typography,
  CardBody,
} from "@material-tailwind/react";
 
export default function CollapseDefault() {
  const [open, setOpen] = React.useState(false);
 
  const toggleOpen = () => setOpen((cur) => !cur);
 
  return (
    <>
      <Button onClick={toggleOpen}>Open Collapse</Button>
      <Collapse open={open}>
        <Card className="my-4 mx-auto w-8/12">
          <CardBody>
            <Typography>
              Use our Tailwind CSS collapse for your website. You can use if for
              accordion, collapsible items and much more.
            </Typography>
          </CardBody>
        </Card>
      </Collapse>
    </>
  );
}

Collapse Props

The following props are available for collapse component. These are the custom props that we've added for the collapse component and you can use all the other native props as well.

AttributeTypeDescriptionDefault
openbooleanIf true the collapse will expandNo default value it's a required prop.
animateAnimateChange collapse animationundefined
classNamestringAdd custom className for collapse''
childrennodeAdd content for collapseNo default value it's a required prop.


For TypeScript Only

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

Types - Animate

type animate = {
  mount?: object;
  unmount?: object;
};

Collapse Theme

Learn how to customize the theme and styles for collapse component, the theme object for collapse component has two main objects:

A. The defaultProps object for setting up the default value for props of collapse component.
B. The styles object for customizing the theme and styles of collapse component.

You can customize the theme and styles of collapse component by adding Tailwind CSS classes as key paired values for objects.



Collapse Theme Object Type

interface CollapseStylesType {
  defaultProps: {
    animate: {
      mount: object;
      unmount: object;
    };
    className: string;
  };
  styles: {
    base: object;
  };
}


For TypeScript Only

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

Collapse Theme Customization

const theme = {
  collapse: {
    defaultProps: {
      animate: {
        unmount: {},
        mount: {},
      },
      className: "",
    },
    styles: {
      base: {
        display: "block",
        width: "w-full",
        basis: "basis-full",
        overflow: "overflow-hidden",
      },
    },
  },
};

Explore More Tailwind CSS Examples

Check out more collapse component examples from Material Tailwind Blocks.