Getting a sketch to load between two images on a web page

I’d like the script with the sketch.js to load between the two images, but it keeps loading at the end of the two images. Just learning HTML so any help would be great! Thanks!

Web page:

Here is the HTML:

<!DOCTYPE html>
	<script src="p5.min.js"></script>
    <script src="p5.dom.min.js"></script>
    <script src="p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
   	<meta charset="utf-8">
	<title>A bunch of failures</title>

	<p><h1>1. Creativity means not being afraid <strike>to fail</strike>
	<br>2. The ideas here now are not as good as the ideas I'm going to put here later
	<br>3. Be excellent to each other</br></h1></p>

    <img src="gifs/CatchIt.gif" width ="400">
	<script src ="sketch.js"></script>
	<img src="gifs/beexcellenttoeachother.jpg" width ="400">

1 Like

A <script> tag isn’t displayable. It’s for embedding code inside an “.html” file:

The JS library “p5.js” indeed creates a <canvas> tag once it runs our “sketch.js” code:

But that happens much later. Those 2 <img> tags are created much earlier than the p5js’ <canvas> tag.

Instead, you should create an empty container tag, such as <p> or <div>, and name an id attribute to it:

For example: <p id=between></p> creates an element which is uniquely identified as “between”.

Then, inside “sketch.js”, call method p5.Element::parent() over the p5.Renderer returned by p5::createCanvas():

createCanvas(400, 400).parent('between');

The statement above makes the <canvas> element that is wrapped inside the p5.Renderer object created by the p5::createCanvas() method to be a child element of another element whose id is “between”.

I’ve refactored & hosted your whole code at the link below. Take a look: :sunglasses:


<!DOCTYPE html>

<title>A bunch of failures</title>

<meta charset=utf-8>
<meta name=viewport content=width=device-width,initial-scale=1>

<link rel=stylesheet href=style.css>

<script defer src=></script>
<!--<script defer src=></script>-->
<!--<script defer src=></script>-->

<script defer src=sketch.js></script>

  <li>Creativity means not being afraid <s>to fail</s>
  <li>The ideas here now are not as good as the ideas I'm going to put here later
  <li>Be excellent to each other

<img width=400 src=>

<p id=between></p>

<img width=400 src=>


@import url('');

h1 {
  font-family: 'Permanent Marker', cursive;

canvas {
  display: block;


 * Place Canvas Between 2 Images (v1.0)
 * by AkaTheWb (Aaron Smith)
 * mod GoToLoop (2019-Jan-22)
 * getting-a-sketch-to-load-between-two-images-on-a-web-page/7734/2

"use strict";

function setup() {
  createCanvas(400, 400).parent('between');

function draw() {
  ellipse(noise(frameCount * .01) * width, height>>1, width>>2, height>>2);

Thank you so much for the detailed reply with sources and refactoring my code…really helps with learning this new material! :muscle::metal::+1::mage:

1 Like