--- productId: material-ui title: React Chip component components: Chip githubLabel: 'scope: chip' materialDesign: https://m2.material.io/components/chips githubSource: packages/mui-material/src/Chip --- # Chip Chips are compact elements that represent an input, attribute, or action. Chips allow users to enter information, make selections, filter content, or trigger actions. While included here as a standalone component, the most common use will be in some form of input, so some of the behavior demonstrated here is not shown in context. ## Basic chip The `Chip` component supports outlined and filled styling. ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function BasicChips() { return ( ); } ``` ## Chip actions You can use the following actions. - Chips with the `onClick` prop defined change appearance on focus, hover, and click. - Chips with the `onDelete` prop defined will display a delete icon which changes appearance on hover. ### Clickable ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function ClickableChips() { const handleClick = () => { console.info('You clicked the Chip.'); }; return ( ); } ``` ### Deletable ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function DeletableChips() { const handleDelete = () => { console.info('You clicked the delete icon.'); }; return ( ); } ``` ### Clickable and deletable ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function ClickableAndDeletableChips() { const handleClick = () => { console.info('You clicked the Chip.'); }; const handleDelete = () => { console.info('You clicked the delete icon.'); }; return ( ); } ``` ### Clickable link ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function ClickableLinkChips() { return ( ); } ``` ### Custom delete icon ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; import DoneIcon from '@mui/icons-material/Done'; import DeleteIcon from '@mui/icons-material/Delete'; export default function CustomDeleteIconChips() { const handleClick = () => { console.info('You clicked the Chip.'); }; const handleDelete = () => { console.info('You clicked the delete icon.'); }; return ( } /> } variant="outlined" /> ); } ``` ## Chip adornments You can add ornaments to the beginning of the component. Use the `avatar` prop to add an avatar or use the `icon` prop to add an icon. ### Avatar chip ```tsx import Avatar from '@mui/material/Avatar'; import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function AvatarChips() { return ( M} label="Avatar" /> } label="Avatar" variant="outlined" /> ); } ``` ### Icon chip ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; import FaceIcon from '@mui/icons-material/Face'; export default function IconChips() { return ( } label="With Icon" /> } label="With Icon" variant="outlined" /> ); } ``` ## Color chip You can use the `color` prop to define a color from theme palette. ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function ColorChips() { return ( ); } ``` ## Sizes chip You can use the `size` prop to define a small Chip. ```tsx import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; export default function SizesChips() { return ( ); } ``` ## Multiline chip By default, Chips displays labels only in a single line. To have them support multiline content, use the `sx` prop to add `height:auto` to the Chip component, and `whiteSpace: normal` to the `label` styles. ```tsx import Chip from '@mui/material/Chip'; import Box from '@mui/material/Box'; export default function MultilineChips() { return ( ); } ``` ## Chip array An example of rendering multiple chips from an array of values. Deleting a chip removes it from the array. Note that since no `onClick` prop is defined, the `Chip` can be focused, but does not gain depth while clicked or touched. ```tsx import * as React from 'react'; import { styled } from '@mui/material/styles'; import Chip from '@mui/material/Chip'; import Paper from '@mui/material/Paper'; import TagFacesIcon from '@mui/icons-material/TagFaces'; interface ChipData { key: number; label: string; } const ListItem = styled('li')(({ theme }) => ({ margin: theme.spacing(0.5), })); export default function ChipsArray() { const [chipData, setChipData] = React.useState([ { key: 0, label: 'Angular' }, { key: 1, label: 'jQuery' }, { key: 2, label: 'Polymer' }, { key: 3, label: 'React' }, { key: 4, label: 'Vue.js' }, ]); const handleDelete = (chipToDelete: ChipData) => () => { setChipData((chips) => chips.filter((chip) => chip.key !== chipToDelete.key)); }; return ( {chipData.map((data) => { let icon; if (data.label === 'React') { icon = ; } return ( ); })} ); } ``` ## Chip playground ```jsx import * as React from 'react'; import Grid from '@mui/material/Grid'; import FormControl from '@mui/material/FormControl'; import FormLabel from '@mui/material/FormLabel'; import FormControlLabel from '@mui/material/FormControlLabel'; import RadioGroup from '@mui/material/RadioGroup'; import Radio from '@mui/material/Radio'; import Avatar from '@mui/material/Avatar'; import Chip from '@mui/material/Chip'; import FaceIcon from '@mui/icons-material/Face'; import DoneIcon from '@mui/icons-material/Done'; import { HighlightedCode } from '@mui/internal-core-docs/HighlightedCode'; function ChipsPlayground() { const [state, setState] = React.useState({ color: 'default', onDelete: 'none', avatar: 'none', icon: 'none', variant: 'filled', size: 'medium', }); const { color, onDelete, avatar, icon, variant, size } = state; const handleChange = (event) => { setState({ ...state, [event.target.name]: event.target.value, }); }; const handleDeleteExample = () => { console.info('You clicked the delete icon.'); }; const colorToCode = color !== 'default' ? `color="${color}" ` : ''; const sizeToCode = size === 'small' ? `size="small" ` : ''; const variantToCode = variant !== 'filled' ? `variant="${variant}" ` : ''; let onDeleteToCode; switch (onDelete) { case 'none': onDeleteToCode = ''; break; case 'custom': onDeleteToCode = 'deleteIcon={} onDelete={handleDelete} '; break; default: onDeleteToCode = 'onDelete={handleDelete} '; break; } let iconToCode; let iconToPlayground; switch (icon) { case 'none': iconToCode = ''; break; default: iconToCode = 'icon={} '; iconToPlayground = ; break; } let avatarToCode; let avatarToPlayground; switch (avatar) { case 'none': avatarToCode = ''; break; case 'img': avatarToCode = 'avatar={} '; avatarToPlayground = ; break; case 'letter': avatarToCode = 'avatar={F} '; avatarToPlayground = F; break; default: break; } if (avatar !== 'none') { iconToCode = ''; iconToPlayground = null; } const jsx = ` `; return ( ({ height: theme.spacing(10) })}> : undefined} onDelete={onDelete !== 'none' ? handleDeleteExample : undefined} avatar={avatarToPlayground} icon={iconToPlayground} variant={variant} size={size} /> variant } label="filled" /> } label="outlined" /> color } label="default" /> } label="primary" /> } label="secondary" /> } label="error" /> } label="info" /> } label="success" /> } label="warning" /> size } label="medium" /> } label="small" /> icon } label="none" /> } label="icon" /> avatar } label="none" /> } label="letter" /> } label="img" /> onDelete } label="none" /> } label="default" /> } label="custom" /> ); } export default ChipsPlayground; ``` ## Accessibility If the Chip is deletable or clickable then it is a button in tab order. When the Chip is focused (for example when tabbing) releasing (`keyup` event) `Backspace` or `Delete` will call the `onDelete` handler while releasing `Escape` will blur the Chip. # Chip API ## Demos For examples and details on the usage of this React component, visit the component demo pages: - [Chip](https://mui.com/material-ui/react-chip/) ## Import ```jsx import Chip from '@mui/material/Chip'; // or import { Chip } from '@mui/material'; ``` ## Props | Name | Type | Default | Required | Description | |------|------|---------|----------|-------------| | avatar | `element` | - | No | | | children | `unsupportedProp` | - | No | | | classes | `object` | - | No | Override or extend the styles applied to the component. | | clickable | `bool` | - | No | | | color | `'default' \| 'primary' \| 'secondary' \| 'error' \| 'info' \| 'success' \| 'warning' \| string` | `'default'` | No | | | component | `elementType` | - | No | | | deleteIcon | `element` | - | No | | | disabled | `bool` | `false` | No | | | icon | `element` | - | No | | | label | `node` | - | No | | | nativeButton | `bool` | - | No | | | onDelete | `func` | - | No | | | size | `'medium' \| 'small' \| string` | `'medium'` | No | | | skipFocusWhenDisabled | `bool` | `false` | No | | | slotProps | `{ label?: func \| object, root?: func \| object }` | `{}` | No | | | slots | `{ label?: elementType, root?: elementType }` | `{}` | No | | | sx | `Array \| func \| object` | - | No | The system prop that allows defining system overrides as well as additional CSS styles. | | variant | `'filled' \| 'outlined' \| string` | `'filled'` | No | | > **Note**: The `ref` is forwarded to the root element (HTMLDivElement). > Any other props supplied will be provided to the root element (native element). ## Theme default props You can use `MuiChip` to change the default props of this component with the theme. ## Slots | Name | Default | Class | Description | |------|---------|-------|-------------| | root | `div` | `.MuiChip-root` | The component that renders the root. | | label | `span` | `.MuiChip-label` | The component that renders the label. | ## CSS ### Rule name | Global class | Rule name | Description | |--------------|-----------|-------------| | - | avatar | Styles applied to the avatar element. | | - | clickable | Styles applied to the root element if `onClick` is defined or `clickable={true}`. | | - | colorDefault | Styles applied to the root element if `color="default"`. | | - | colorError | Styles applied to the root element if `color="error"`. | | - | colorInfo | Styles applied to the root element if `color="info"`. | | - | colorPrimary | Styles applied to the root element if `color="primary"`. | | - | colorSecondary | Styles applied to the root element if `color="secondary"`. | | - | colorSuccess | Styles applied to the root element if `color="success"`. | | - | colorWarning | Styles applied to the root element if `color="warning"`. | | - | deletable | Styles applied to the root element if `onDelete` is defined. | | - | deleteIcon | Styles applied to the deleteIcon element. | | `.Mui-disabled` | - | State class applied to the root element if `disabled={true}`. | | - | filled | Styles applied to the root element if `variant="filled"`. | | `.Mui-focusVisible` | - | State class applied to the root element if keyboard focused. | | - | icon | Styles applied to the icon element. | | - | outlined | Styles applied to the root element if `variant="outlined"`. | | - | sizeMedium | Styles applied to the root element if `size="medium"`. | | - | sizeSmall | Styles applied to the root element if `size="small"`. | ## Source code If you did not find the information on this page, consider having a look at the implementation of the component for more detail. - [/packages/mui-material/src/Chip/Chip.js](https://github.com/mui/material-ui/tree/HEAD/packages/mui-material/src/Chip/Chip.js)