Thanks for your suggestion. The example I sent you yesterday was rather stupid

I thought about it during the night and realised that the <p> element was superfluous. I could just as well have put the spaces in the span element. I tried with margins 0,0,0,0 but the 'empty line' above the paragraph still appears. But I have just made a breakthrough

This seems to be the solution:
objs[i+1].innerHTML= '<span><p style="float:left;clear:none;"> </p>' + objs[i+1].textContent +'</span>' i.e. putting unbreakable spaces in the <p> tag and removing the text-indent instruction.
I am working towards a radical change in my 'animated reading' system. I think I can use your spans like this:
const span = document.getElementById('syspageFrame').contentWindow.document.getElementById(40)
span.style="background-color:blue;color:white" so that instead of selecting text in the textarea I can change the style of each span in the div which produces the same result and solves certain other complicated problems but I won't bore you with all the details.