Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js | createSpan() Function

Improve Article
Save Article
  • Last Updated : 26 Feb, 2020
Improve Article
Save Article

The createSpan() function is used to create a span element in the DOM with the given optional inner 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 is an optional parameter.

Return Value: It returns a pointer to the p5.Element with the created node.

The example below illustrate the createSpan() function in p5.js:


function setup() {
  createCanvas(600, 300);
  text("Click on the button to create" +
       "<span> elements at random positions.", 20, 20)
  genBtn = createButton("Create span element").position(30, 40);
function spawnSpan() {
  newSpan = createSpan("This is a <b>span</b> element"+
                       " with custom <i>innerHTML</i>.");
  newSpan.position(random(50, 500), random(50, 300));


Online editor:

Environment Setup:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!