Looking to create a basic typing test app using HTML, CSS and JS. My goal is to have placeholder text displayed in the input box so users know what to type as they type. Misalignments between the placeholder text and user input will indicate mistakes. After hours of trial and error, I've developed two subpar solutions:
<div id='test' class="placeholder" data-value="This appears in the box!">
<textarea id="typed" name="typed" cols=50 rows=15></div>
CSS:
.placeholder
{
position: relative;
}
.placeholder::after
{
position: absolute;
left: 2px;
top: 2px;
content: attr(data-value);
pointer-events: none;
opacity: 0.6;
text-align: left;
}
While this method works well, it struggles with handling newlines properly. Various attempts like \u000A, \x0A, \r\n haven't yielded success.
Option two involves utilizing the placeholder attribute:
<textarea placeholder="line1
line2" id="typed" name="typed" cols=50 rows=15></textarea>
This approach displays the text correctly but it disappears when users begin typing.
Anyone aware of how to keep standard placeholder text visible permanently or any other workaround for correct formatting?