How to import style from html file?

In LibreOffice Writer I select the menu

Insert>Text from File

I choose an html file and it mostly works fine.

I want to import some styles with the document.
In the html file its with the p> tag, e,g. p class=mystyle>abc


It works except that it messes up the formatting by adding a paragraph break. (its inside a table so it’s a disaster.)

I have tried importing the same style with
span, div, pre, b
none work.

Is there a tag pair I can use that Writer will recognize?

You must understand Writer is not an HTML composer, i.e. you won’t write manually HTML tags, elements or attributes.

When formatting, Writer understands its own styles. Formatting is controlled by paragraph, character, list and frame styles (page styles are not relevant for HTML). You can also experiment with direct formatting, i.e. applying formatting variants with toolbar buttons, but this ersatz for styles is not recommended.

When you save the document with filename extension .html, the internal structure is translated by an export filter, converting the styles (and anonymous formatting) to CSS. You can’t inject directly CSS or interfere with HTML tag attributes.

In Writer, whenever you hit Return, this creates a paragraph (not a line break), eventually empty (this explains why you should never use the Return key for vertical spacing). Then, paragraphs are always translated as <p class=some_style>Contents of paragraph</p>. Empty paragraphs come as <p class=some_style></p> resulting in blank space (at least padding+border size).

To answer your question, use Writer “as usual” to layout your document, without caring for CSS styles or switch to an HTML dedicated composer.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

I have decided to use images instead of tables which resolves the above problem. I have written a short program which converts the tables to jpgs. This also removes the problem of tables splitting over pages.