How to remove default padding from material ui List Item?

You can override the root class of the ListItem component and pass the padding you want.

const styles = theme => ({
  root: {
    width: "100%",
    maxWidth: 360,
    backgroundColor: theme.palette.background.paper
  },

  item: {
    padding: 0
  }
});

function SimpleList(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <List component="nav">
        <ListItem button classes={{ root: classes.item }}>
          <ListItemText primary="Item 01" />
        </ListItem>
        <ListItem button classes={{ root: classes.item }}>
          <ListItemText primary="Item 02" />
        </ListItem>
        <ListItem button classes={{ root: classes.item }}>
          <ListItemText primary="Item 03" />
        </ListItem>
      </List>
    </div>
  );
}

See working sample.


For anyone else coming here the easy way to remove the default padding from the list is to use the disablePadding prop on the List Component.

https://material-ui.com/api/list/

enter image description here


    import React from 'react'
    import List from '@material-ui/core/List'
    import ListItem from '@material-ui/core/ListItem'
    import ListItemText from '@material-ui/core/ListItemText'
    
    function Sidebar() {
      return (
        <List disablePadding>
          <ListItem button>
            <ListItemText>Home</ListItemText>
          </ListItem>
          <ListItem button>
            <ListItemText>Billing</ListItemText>
          </ListItem>
          <ListItem button>
            <ListItemText>Settings</ListItemText>
          </ListItem>
        </List>
      )
    }
    
    export default Sidebar

Tags:

Material Ui