28

I know there are HTML entities for 1/2, 1/4, and 3/4, but are there others? Like 1/3 or 1/8? Is there a good way to encode arbitrary fractions?

1

8 Answers 8

43

how about 1516? (<sup>15</sup>&frasl;<sub>16</sub>)

1
  • 3
    Ideally would use &frasl; for the slash
    – dajoto
    Nov 6, 2013 at 12:03
29
1/2 → &#189; or &frac12;
1/4 → &#188; or &frac14;
3/4 → &#190; or &frac34;
1/8 → &#8539; or &frac18;
3/8 → &#8540; or &frac38;
5/8 → &#8541; or &frac58;
7/8 → &#8542; or &frac78;
1/3 → &#8531;
2/3 → &#8532;
1/5 → &#8533;
2/5 → &#8534;
3/5 → &#8535;
4/5 → &#8536;
1/6 → &#8537;
5/6 → &#8538;

...but you could also encode them as decimals: 15/16 = 0.9375 ;)

1
  • 2
    The equivalent decimal codes do, however, appear to work for ⅛ to ⅞ in IE. I'll update my answer to include them.
    – scronide
    Feb 28, 2012 at 17:49
11

For the existing fractions as Unicode codepoints (which are mapped to by HTML entities), search for "vulgar fraction" in the Unicode Character Names Index.

Now, for generic fractions, which work in HTML but also work in plain text, use the super- and subscript digits (see Unicode Codepoint Chart, search for "Superscripts") separated by the fraction slash character.

Your example implemented as above:

¹⁵⁄₁₆

0
1

Isn't just 15/16ths alright? Or even 15/16ths (15/16<sup>ths</sup>)?

1
  • 7
    There's no need to spell out the "ths". 15/16 is pronounced "fifteen sixteenths". Oct 6, 2008 at 17:45
1

For more complex scenarios there is also MathML. The support for this is slowly getting better. Internet Explorer seems to lag behind with this as well.

0

There is also a standard called MathML. But is for XML unfortunately. However if you have more expressions you might consider switching to basic XML.

0

This would depend on your exact needs and audience. For most purposes many methods would be appropriate. 15/16, 15 parts of 16, 93.75%, 15/16 all mean the same, you might even use symbols like ++++++++++++++-

For some more complex scenarios you will need more complex solutions more like LaTeX than html. I believe there are also server side components that take LaTeX descriptions and create images that are browser compatible, such as described here: http://www.fauskes.net/nb/htmleqII/

0

In HTML, this can be done with Unicode code 2044, preceded by &#x and ending with a semicolon. The whole thing is placed between the numerator and the denominator.

For instance, with this solution, 15 divided by 16 in HTML is rendered like this: 15⁄16

This works for combinations of integers acting as numerators and denominators.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.