If you have an iPad or a Kindle K3 or higher with the latest firmware and aren't interested in publishing books with KDP, you could give
pseudo-elements a try, because they allow you to automatically add line numbers. They also allow you add special formatting to every nth element. (I used both features in my simple test file.)
Unfortunately, the majority of ePub readers and apps don't support pseudo-elements and you can't use
counter pseudo-elements in KDP Kindle books according to the official publishing guidelines, even though they work fine.
I slapped together a very simple test file that displays fine with Sigil, Calibre Book Viewer, iBooks (after ePub3 conversion) and on my Kindle PW2. However, it doesn't display correctly with ADE4, even if it's converted to an ePub3 file.
I formatted the poem as an unordered list:
Spoiler:
Code:
<h3>The Raven by Edgar Alan Poe</h3>
<ul>
<li>Once upon a midnight dreary, while I pondered, weak and weary,</li>
<li>Over many a quaint and curious volume of forgotten lore,</li>
<li>While I nodded, nearly napping, suddenly there came a tapping,</li>
<li>As of some one gently rapping, rapping at my chamber door.</li>
<li>"'Tis some visiter," I muttered, "tapping at my chamber door—</li>
<li>Only this, and nothing more."</li>
<li>Ah, distinctly I remember it was in the bleak December,</li>
<li>And each separate dying ember wrought its ghost upon the floor.</li>
<li>Eagerly I wished the morrow;—vainly I had tried to borrow</li>
<li>From my books surcease of sorrow—sorrow for the lost Lenore—</li>
<li>For the rare and radiant maiden whom the angels name Lenore—</li>
<li>Nameless here for evermore.</li>
<!-- more lines ... -->
</ul>
And used the following minimal CSS: