Try the following configuration file:
\Preamble{xhtml}
\tikzset{every node/.style={/pgf/tex4ht node/escape=true}}
\begin{document}
\EndPreamble
From the TikZ manual:
Selects the rendering method for a text node with the tex4ht driver.
When this key is set to false, text is translated P R into svg text,
which is somewhat limited: simple characters (letters, numerals,
punctuation, , , . . . ), subscripts and superscripts (but not sub-
subscripts) will display but everything else will be filtered out,
ignored or will produce invalid html code (in the worst case). This
means that two kind of texts render reasonably well:
First, plain text without math mode, special characters or anything else special.
Second, very simple mathematical text that contains subscripts or superscripts. Even then, variables are not correctly set in italics
and, in general, text simple does not look very nice. If you use text
that contains anything special, even something as simple as $\alpha$,
this may corrupt the graphic.
\tikz \node[draw,/pgf/tex4ht node/escape=false]
{Example :
$(a+b)^2=a^2+2ab+b^2$};
When you write node[/pgf/tex4ht
node/escape=true] {htexti}, pgf escapes back to html to render the
htexti. This method produces valid html code in most cases and the
support for complicated text nodes is much better since code that
renders well outside a {pgfpicture}, should also render well inside a
text node. Another advantage is that inside text nodes with fixed
width, html will produce line breaks for long lines. On the other
hand, you need a browser with good svg support to display the picture.
Also, the text will display differently, depending on your browsers,
the fonts you have on your system and your settings. Finally, pgf has
to guess the size of the text rendered by the browser to scale it and
prevent it from sticking from the node. When it fails, the text will
be either cropped or too small.
The result on your file:
Another possibility is to use an alternative driver for tex4ht
, which use Dvisvgm for the SVG generation. It has much better support for fonts and other advanced SVG features.
The TeX file needs to be updated to use the driver:
\documentclass{article}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {-3,...,3} { \draw(\x,0.25) --(\x,0)node[below]{\x}; }
\foreach \x in {-2.5,...,2.5} { \draw(\x,0.18) --(\x,0); }
\draw[thick,<->](-3.5,0)--(3.5,0);
\filldraw[blue!50!white](1.5,0) circle (1mm);
\draw[red] (-3.5,-1) rectangle (3.5,1); % make bounding box higher
\end{tikzpicture}
\end{document}
The result: