Search code examples
htmlstringsubscriptsuperscript

Is there a way to write small text directly over particular letters in HTML?


Complete amateur here. I am working on a little personal project and need to be able to put numbers directly over over certain letters like this:

enter image description here

My current method is to just embed the equations as jpegs, but would like to know if there is a better way to do this (preferably, but not necessarily, in pure HTML)? (Hopefully something like the /above function on Microsoft word) Thank you for your help.


Solution

  • Use the superscript and subscript tags.

    sup {
      left: -.5em;
      top: -.5em;
      margin-left: -1em;
      position: relative;
    }
    K<sub>2</sub>Cr<sub>2</sub><sup>+6</sup>O<sub>7</sub>

    Are you looking for something like this? It may require some fine-tuning based on the exact formula you are trying to represent, but I think it works as a proof-of-concept.