It is necessary that li in the line was not more than 4 pieces, after exceeding the limit, the new li was inserted into the second row. no more than two rows, width = 300px
var arr = []; var arrList = ""; isHobbies = function() { var str = document.getElementById('hobbies'); var theStr = str.value; arr.push(theStr); document.getElementById("str").innerHTML = ""; for (var i = 0; i < arr.length; i++) { arrList = "<li>" + arr[i] + "</li>"; document.getElementById("str").innerHTML += arrList; } } .interes { display: flex; } <div class="hob"> <label for="hobbies">Интересы</label> <input type="text" id="hobbies" placeholder="Ваш интерес?" name="" value=""> <input type="button" id="addHobbies" name="" value="Добавить интерес" onclick="isHobbies()"> <div id="str" class="interes"> </div> </div>