Search code examples
htmlfractions

How to represent fractions in html


I want to represent fractions in html and the code I am using now is this:

<sup>3</sup>&frasl;<sub>8</sub>

And it looks like this:

enter image description here

But I want to represent it something like this:

enter image description here

How do I change it?

Need some guidance on this.


Solution

  • It is not possible through pure HTML. But you can create that type of fraction using a bit of CSS.

    .fraction {
      position: relative;
      width: 1em;
      font-size: 2em;
    }
    .numerator {
      border-bottom: 2px solid black;
      text-align: center;
    }
    .denominator {
      border-right: 2px solid black;
      width: 0.75em;
      text-align: center;
    }
    <div class="fraction">
      <div class="numerator">3</div>
      <div class="denominator">8</div>
    </div>