<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
const MaxInputLength = 100;
const { useState, useEffect } = React;
const [inputValue, setInputValue] = useState('');
const adjustWidth = (event) => {
const value = event.target.value;
if (value.length === 0) {
event.target.style.width = 'initial';
} else if (value.length > 20 && value.length < MaxInputLength) {
event.target.style.width = `${value.length * 6 + 30}px`; // 5 * 6 + 30 for extra space
<div className='container'>
<h2 className='header'>React Js Increase input width dynamically:</h2>
placeholder="Type something.."
ReactDOM.render(<App />, document.getElementById("app"));
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: width 0.3s ease;
/* Smooth width transition */
/* Prevent input from overflowing the container */