4

How to write fractions in html? I want to write some like this.."3 ½ years" in html. How to do it?

html:

  <html>
      <body>
          <p>3 1/2 years</p>
      </body>
 </html>
Nag
  • 806
  • 1
  • 13
  • 28

4 Answers4

3

You can use;

&frac12;  3 ½

or you can use ASCII character code;

&#189;   3 ½

Hope helps;

Berkay Yaylacı
  • 4,383
  • 2
  • 20
  • 37
2

You can try this:

 3<sup>1</sup>&frasl;<sub>2</sub>years
Geeky Ninja
  • 6,002
  • 8
  • 41
  • 54
2

You can use this code:

&frac12

Then, your code should like this:

<p>3 &frac12 years</p>

3 &frac12 years

Shu Peng
  • 19
  • 2
  • `&frac12` without `;` is a parse error. – Oriol Jul 01 '16 at 12:01
  • @Oriol It's ok without `;` in Chrome. I have not test in other browsers, maybe with `;` is standard code style. – Shu Peng Jul 01 '16 at 12:10
  • @ShuPeng HTML is able to recover from errors, but that does not mean you should write invalid code. Try it in XHTML and you will see the draconian error handling. – Oriol Jul 01 '16 at 13:25
1
¼   &frac14;
½   &frac12;

Just type nominator and denominator at the end

user3041764
  • 817
  • 10
  • 35