JSFiddle - React, Tailwind, and code Playground

HTML

<div class="parent">
  Contrary to popular belief Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
</div>

CSS

.parent {
    width: 200px;
}

span {
    background: yellow;
}

JavaScript

var element = document.getElementsByClassName("parent")[0];
var elementHeight = element.clientHeight;
var words = element.innerText.split(" ");
var lastLine = ""; 

element.innerText = "";
words.forEach(function(value, index){
    element.innerText += " " + value;  
    if (element.clientHeight == elementHeight)
        lastLine += value + " ";
});

var newHtml = element.innerHTML.replace(lastLine.trim(), "<span>" + lastLine + "</span>");
element.innerHTML = newHtml;