<!DOCTYPE html> <style> div { color: red; } div::first-line { color: green } #table { display: inline-table; } #caption { display: table-caption; } #tbody { display: table-row-group; } </style> <div id="x"> <span id="table"> <span id="tbody">be green</span> </span> </div> <script> x.offsetWidth; var caption = document.createElement("span"); caption.id = "caption"; caption.textContent = "This should"; table.appendChild(caption); </script>