This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Compile (modified)TeXSave


FilledSmallSquareHTMLSave["file.html"] saves an HTML version of the currently selected notebook in the front end.

FilledSmallSquareHTMLSave["file.html", "source.nb"] saves an HTML version of the notebook from the file source.nb.

FilledSmallSquareHTMLSave["file.html", notebook] saves an HTML version of the notebook corresponding to the specified notebook object.

FilledSmallSquareHTMLSave has options for specifying such features as how to include formulas, whether to make links for closed cell groups, and what correspondence to set up between notebook styles and HTML tags.

FilledSmallSquareHTMLSave normally saves graphics in separate image files.

FilledSmallSquareHTMLSave can often be accessed from an item in the Save As Special menu in the notebook front end.

FilledSmallSquare See The Mathematica Book: Section 1.11.7.

FilledSmallSquare See also: Export, MathMLForm, TeXSave, Display.

Additional Information


Mathematica can translate notebooks, as well as cells, lists of cells, boxes, or other notebook elements into HTML. HTMLSave wraps the input in a notebook before conversion. Therefore, the output of HTMLSave is always a complete HTML document, and not merely a fragment of HTML.

Invoking HTMLSave

You may invoke HTMLSave from the File Save As Special menu command in the notebook front end. You may also invoke HTMLSave from the kernel if it is connected to a notebook front end. The front end converts typeset expressions or graphs to GIFs and provides document settings (such as style sheet information) to HTMLSave.

HTMLSave Options

When you invoke HTMLSave from the kernel, you may set the option ConversionOptions.

The option ConversionOptions for HTMLSave.

HTMLSave Output

The output produced by HTMLSave conforms to the HTML 4 standard. The output consists of one or more HTML files and two directories, Images and Links. When using the Save As Special menu command, a dialog box appears for specifying the name of the file. When using the kernel, you name the output via the first argument to HTMLSave. If you do not provide an extension to the name given to the output (for example, index.html), HTMLSave creates a directory by the name you provided. This directory then contains the HTML files and the Images and Links directories.

HTMLSave writes out nearly all inline typeset expressions and many block-level typeset expressions as GIF files. There are two general exceptions:

1. Choosing HTMLSave from the File Save As Special submenu (or using MathOutput -> MathML option from the kernel) writes out the expression marked up with MathML tags.

2. If a GridBox is the top level of a cell, an HTML table will be generated.


HTMLSave uses hyperlinks in your Mathematica notebook to generate HTML links and produce additional HTML documents. For example, if you have a link to a notebook called notebook2.nb in the notebook you are converting via HTMLSave, Mathematica converts the Mathematica hyperlink to an HTML hyperlink and converts the notebook notebook2.nb to HTML.

There is one exception: links to online Mathematica documentation generate an empty hyperlink in the HTMLSave output file. If Mathematica were to convert all linked documentation, you would quickly have several hundred megabytes of HTML documentation, due to the extensive cross referencing in the online documentation. Much of the online documentation is available in HTML form on the web at

HTMLSave also generates hyperlinks from closed cell groups. The head cell of the group becomes the hyperlink, and the remainder of the group becomes a separate HTML document.


HTMLSave writes out top-level GridBoxes as tables. GridBoxes are counted as top-level if they are in the topmost box or if they are wrapped in non-layout boxes, which are StyleBox, TagBox, and InterpretationBox.

HTML tables are block-level elements, which means that they have an explicit break or return at both the beginning and end. Since HTML tables are never block-level elements, Mathematica inline GridBoxes cannot be rendered as tables and are saved as GIFs.

Principles of Notebook Conversion

HTML is a markup language rather than a document layout language. This means that it defines elements by their purpose in the document (for example, title, list element, and so on) rather than their actual appearance (for example, 14-point bold Palatino).

You should always mark up elements according to their purpose. If you must add appearance tags, such as <B> and <FONT>, use them in addition to structural tags, such as <CODE> or <EM>. For the difference between appearance and structural tags, consult any introductory HTML book.

Here is a cell expression that uses the Subsubsection style.

Cell[TextData["Principles of Notebook Conversion"], "Subsubsection"]

This is the corresponding output written to the HTML file after conversion.

<H5>Principles of Notebook Conversion</H5>

The output does not explicitly specify the font choice or other aspects of its appearance. Subsubsection items in Mathematica under the default style sheet appear in 12-point bold Times with a small filled square cell dingbat, but different browsers will display a level 5 heading quite differently.

For cells that contain two-dimensional typeset math expressions, HTMLSave generates a GIF. Selecting HTML/MathML from the File Save As Special menu (or using MathOutput -> MathML option from the kernel) writes out the expression marked up with MathML tags.

Here is a cell expression that uses the Text style and contains aTraditionalForm inline cell.


"The Pythagorean theorem states that ",




SuperscriptBox["c", "2"], "=", " ",



RowBox["2", " "]], "+", " ",

SuperscriptBox["b", "2"]]], TraditionalForm]]],


], "Text"]

This is what is written to the HTML output file using File Save As Special HTML.

<P> The Pythagorean theorem states that <IMG


BORDER="0" ALT="[Graphics:Images/inline1_gr_1.gif]" WIDTH="73"


ALIGN="absmiddle" >. </P>

This is what is written to the HTML output file using File Save As Special HTML/MathML.

<P> The Pythagorean theorem states that























. </P>

Adjusting Output via Style Sheets

The output of HTMLSave can be adjusted through ConversionRules, specifying which HTML tags, or nested tags, appear in the HTML document.

Here is the general structure of ConversionRules.

ConversionRules ->

"HTML" -> "inline beginning tags", "inline ending tags",

"block-level beginning tags", "block-level ending tags".

As you can see from the form of the ConversionRule, HTML draws a strong distinction between block-level elements and inline elements. It is important when you add ConversionRules to your style definition cells to include both the inline rule (the first set of tags) as well as the block-level rule (the second set of tags). The block-level rule should have an outermost tag that is block-level, such as <P> or <DIV>. The inline rule should never have an outermost tag that is block-level.

Here is a style definition cell that contains a conversion rule for the InlineFormula style from the default style sheet.


other cell options, ... ,

ConversionRules ->

"HTML" -> "<B><CODE>", "</CODE></B>", "<P><B><CODE>",



When HTMLSave converts an item in the InlineFormula style, it wraps the item in bold and code tags if the item is inline, and adds a paragraph tag if the item is block-level.

Here is a cell expression in the InlineFormula style.

Cell[TextData["x = a + b"],


Here is the appearance of the converted cell in the HTML output file.

<B><CODE>x = a + b</CODE></B>

Getting Updates to the Source Code

Despite the large number of options for adjusting HTMLSave output via style sheet conversion rules, there may be circumstances where you need to make changes at a deeper level. Since HTMLSave is implemented as top-level Mathematica code, the source code is available in Mathematica package format.

The package can be downloaded from the web at

Compile (modified)TeXSave