How to Write LaTeX Math in HTML Using MathJax

Published July 25, 2025, 7:25 p.m. by james

If you want to display math formulas on a website using LaTeX syntax, MathJax is the best choice. It renders LaTeX math directly in the browser using JavaScript.

Step 1: Include MathJax

Add the following script tags to your HTML. This enables MathJax and tells it how to interpret inline math.

<script> MathJax = { tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] } }; </script> <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"> </script>

Step 2: Write LaTeX Math in HTML

You can now include math formulas in your HTML using either block or inline syntax.

Block Example

Raw LaTeX code:

$$E = mc^2$$

Rendered result:

$$E = mc^2$$

Inline Example

Raw LaTeX code inside a sentence:

The derivative is given by \\( f'(x) = \\lim_{h \\to 0} \\frac{f(x+h)-f(x)}{h} \\)

Rendered result:

The derivative is given by \( f'(x) = \lim_{h \to 0} \frac{f(x+h)-f(x)}{h} \).

Tips

Conclusion

With MathJax, you can write math in LaTeX syntax directly in your HTML. It's ideal for tutorials, documentation, and educational content. To show raw code, remember to escape special characters so that MathJax doesn't render them.

Share this post

Similar posts

There are no similar posts yet.

comment

There are no comments yet.

Add a new comment