p5.js createInput() Function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The createInput() function is used to create an input element in the DOM for accepting text input. The optional parameters can be used to set the type of input that can be entered. You can use the set() function to define the length of the box. Syntax: createInput(value, type) Parameters: This function accepts two parameters as mentioned above and described below: value: This string parameter used to set the default value of the input.type: This is a string parameter which sets the type of input. It can have values such as 'text', 'password', etc for accepting text with that specific format. Return Value: It returns a pointer to the p5.Element with the created node. Below examples illustrate the createInput() function in p5.js: Example 1: javascript function setup() { createCanvas(300, 200); textSize(18); text("Enter username:", 20, 20); usernameInput = createInput('Your username', 'text'); usernameInput.position(30, 40); text("Enter password:", 20, 80); passInput = createInput('', 'password'); passInput.position(30, 100); text("Enter Date of Birth:", 20, 140); dobInput = createInput('1970-01-01', 'date'); dobInput.position(30, 160); } Output: Example 2: javascript function setup() { createCanvas(600, 300); textSize(28); text("Write in the input box to display the text", 20, 40); // Create input element let inputElem = createInput(''); inputElem.input(onInput); inputElem.position(30, 60) } function onInput() { clear(); text("Write in the input box to display the text", 20, 40); fill("green") strokeWeight(10) rect(0, 100, 600, 100) // Display the text entered fill("black") text(this.value(), 20, 140) } Output: Online editor: https://editor.p5js.org/ Environment Setup: https://www.geeksforgeeks.org/javascript/p5-js-soundfile-object-installation-and-methods/ Reference: https://p5js.org/reference/#/p5/createInput Comment More infoAdvertise with us Next Article p5.js char() function S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads p5.js createFileInput() Function The createFileInput() function is used to create an input element with the type of 'file' that can be used by the user to select local files to be used in the sketch. It also supports the selection of multiple files if required. Syntax: createFileInput(callback, multiple) Parameters: This function a 2 min read p5.js createWriter() Function The createWriter() function in p5.js is used to create a p5.PrintWriter object that can be used to write or print to various available streams. Syntax: createWriter( name, [extension] ) Parameters: This function accepts two parameters as mentioned above and described below. name: It is a string that 2 min read p5.js createSpan() Function The createSpan() function is used to create a span element in the DOM with the given optional inner html. Syntax: createSpan([html]) Parameters: This function accepts a single parameter as mentioned above and described below: html: It is a string with the innerHTML of the span element. It 1 min read p5.js | attribute() Function The attribute() function is used to add a new attribute or change the value of an existing attribute on the specified element. If the attribute does not specify any value it returns the value of the given attribute, or null if the attribute is not set. Note: This function requires the p5.dom library 1 min read p5.js char() function The char() function in p5.js is used to convert the given string or number value into its corresponding single-character string representation. If the input parameter is a string value then at first it gets converted into its integer equivalent internally after that its single-character string is re 3 min read p5.js Introduction p5.js is a JavaScript library used for creative coding. It is based on Processing which is a creative coding environment. The main focus of processing is to make it easy as possible for beginners to learn how to program interactive, graphical applications, to make a programming language more user-fr 2 min read Like