Search code examples
javascriptcssreactjsmaterial-uitooltip

How to adjust Material UI Tooltip font size?


I implemented a tooltip with Material UI but the fontSize is too small. And I can't change it with a .scss.

import React from "react";
import "./InfoTooltip.scss";
import InfoIcon from '@material-ui/icons/Info';
import Tooltip from '@material-ui/core/Tooltip';

const InfoTooltip: React.FC<{ children?: any }> = ({ children }) => {
  const [label, ...rest] = children;
  return (
    <div className="info-tooltip-container">
      <div className="label-container">
        <Tooltip title={label}>
          <InfoIcon style={{ fontSize: '24px' }} />
        </Tooltip>
      </div>
      {rest}
    </div>
  );
};

export default InfoTooltip;
.info-tooltip-container {
  .label-container {
    font-size: 18px;
  }
  label {
    font-size: 18px;
  }
}

https://mui.com/material-ui/react-tooltip/


Solution

  • You can add a customized component directly to props title.

    If needed, you can add whatever inline-styles to the component you just added.

    Include the font-size

    <Tooltip title={<h1 style={{ color: "lightblue" }}>title</h1>}>
      <InfoIcon />
    </Tooltip>
    

    enter image description here


    Refer: MUI tooltip document: customized-tooltips