# htlatex-produced HTML does not center correctly

If I run htlatex on

\documentclass[12pt]{article}

\begin{document}

Bla bla bla bla

\begin{center} x \end{center} \end{document}


with the setting in this question I get the code below, but my browser (mozilla firefox) does not properly center "x". How can I redefine the way that center is handled to just use some simple html tag (which my browser does understand correctly)?

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->
<html xmlns="http://www.w3.org/1999/xhtml"   >
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<!-- -css,NoFonts,html,xhtml -->
<meta name="src" content="a.tex" />
<meta name="date" content="2016-10-16 19:12:00" />
<body  >
<p>Bla bla bla bla    </p>
<div class="center"  >
<p> </p>
<p>x</p>  </div>
</body>
</html>

• you are using code answering a question that explicitly asks that the css that produces the style is not generated, so in this case you need to provide the css for the .center class to centre the text. Or use the default setting and let tex4ht generate the css. Oct 16, 2016 at 23:27

The centering is done by CSS, so it can't work if you disable it's use in the document. <center> tag exists, which is deprecated in HTML 5, but you can try to use it, if you really don't want to use CSS.

Try the following .cfg file:

\Preamble{xhtml,-css,NoFonts}

\def\FinishPar{\ifvmode\IgnorePar\fi\EndP}
\ConfigureEnv{center}{}{}{\FinishPar\HCode{<center>}}{\FinishPar\HCode{</center>}}
\begin{document}

\EndPreamble


Options -css,NoFonts are included in the config file, so you don't have to specify them on the command line anymore. \FinishPar is helper macro to close paragraph tags at correct places. \ConfigureEnv can be used to configure environments. Because center environment is implemented using list, is is necessary to pass the custom tags in fourth and fifth arguments of \ConfigureEnv.

The other way would be to provide custom CSS file, hello.css:

div.center{
text-align:center;
margin-left:auto;
margin-right:auto;
}


and the .cfg file:

\Preamble{xhtml,-css,NoFonts}


This example just add link to the custom CSS file to the document.