Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering the placeholder for a Textfield MUI

I am trying to align a Placeholder to be centered within the Text-Field. Is there a way to do this? applying text-align: center to the input is not centering the placeholder.

like image 948
Rob Terrell Avatar asked Oct 23 '25 02:10

Rob Terrell


1 Answers

You can use the &::placeholder pseudoselector on input classname like below

 import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";

const useStyles = makeStyles(theme => ({
  input: {
    "&::placeholder": {
      color: "red",
      textAlign: "center"
    }
  }
}));

export default function Inputs() {
  const classes = useStyles();

  return (
    <TextField
      placeholder="Placeholder"
      InputProps={{ classes: { input: classes.input } }}
    />
  );
}

A working sandbox project link

like image 145
Harsh kurra Avatar answered Oct 27 '25 02:10

Harsh kurra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!