navigation
Word Into HTML Coverter

Word into HTML Converter

Word into HTML can quickly create html code converting all the text inside your word document to html

  1. Upload your Word file
  2. Click convert Word to HTML
  3. Check the result below
infos on paragraphs

You can add more HTML tags in the generated HTML code and check the rendering.

Html code

Rendered page

How does Word Into HTML Converter works?

Word Into HTML is designed to convert .docx documents, such as those created by Microsoft Word, Google Docs and LibreOffice, and convert them to HTML. Word Into HTML aims to produce simple and clean HTML by using semantic information in the document, and ignoring other details. For instance, Word Into HTML converts any paragraph with the style Heading 1 to h1 elements, rather than attempting to exactly copy the styling (font, text size, colour, etc.) of the heading.

There's a large mismatch between the structure used by .docx and the structure of HTML, meaning that the conversion is unlikely to be perfect for more complicated documents. Word Into HTML works best if you only use styles to semantically mark up your document.

The following features are currently supported:

  • Headings.
  • Lists.
  • Customisable mapping from your own docx styles to HTML. For instance, you could convert WarningHeading to h1.warning by providing an appropriate style mapping.
  • Tables. The formatting of the table itself, such as borders, is currently ignored, but the formatting of the text is treated the same as in the rest of the document.
  • Footnotes and endnotes.
  • Images.
  • Bold, italics, underlines, strikethrough, superscript and subscript.
  • Links.
  • Line breaks.
  • Text boxes. The contents of the text box are treated as a separate paragraph that appears after the paragraph containing the text box.
  • Comments.

Usage od Word Into HTML

You can convert docx files by passing the path to the docx file and the output file.

If no output file is specified, output is written to stdout instead.

The output is an HTML fragment, rather than a full HTML document, encoded with UTF-8. Since the encoding is not explicitly set in the fragment, opening the output file in a web browser may cause Unicode characters to be rendered incorrectly if the browser doesn't default to UTF-8.

Images

By default, images are included inline in the output HTML.

Styles

A custom style map can be read from a file. For instance:

Markdown

Markdown support is deprecated.

Basic conversion

To convert an existing .docx file to HTML be sure that your file is an authentic docx and not corrupted

Custom style map

By default, this tool maps some common .docx styles to HTML elements. For instance, a paragraph with the style name Heading 1 is converted to a h1 element. For instance, paragraphs with the style name Section Title should be converted to h1 elements, and paragraphs with the style name Subsection Title should be converted to h2 elements.

Custom image handlers

By default, images are converted to <img> elements with the source included inline in the src attribute.

Bold

By default, bold text is wrapped in <strong> tags.

Italic

By default, italic text is wrapped in <em> tags.

Underline

By default, the underlining of any text is ignored since underlining can be confused with links in HTML documents.

Strikethrough

By default, strikethrough text is wrapped in <s> tags.

Comments

By default, comments are ignored. To include comments in the generated HTML.

Comments will be appended to the end of the document, with links to the comments wrapped using the specified style mapping.

Writing style maps

A style map is made up of a number of style mappings separated by new lines. Blank lines and lines starting with # are ignored.

A style mapping has two parts:

  • On the left, before the arrow, is the document element matcher.
  • On the right, after the arrow, is the HTML path.

When converting each paragraph, this tool finds the first style mapping where the document element matcher matches the current paragraph. Word Into HTML then ensures the HTML path is satisfied.

Freshness Word Into Html Converter

When writing style mappings, it's helpful to understand Word Into HTML's notion of freshness. When generating, Word Into HTML will only close an HTML element when necessary. Otherwise, elements are reused.

For instance, suppose one of the specified style mappings is p[style-name='Heading 1'] => h1. If Word Into HTML encounters a .docx paragraph with the style name Heading 1, the .docx paragraph is converted to a h1 element with the same text. If the next .docx paragraph also has the style name Heading 1, then the text of that paragraph will be appended to the existing h1 element, rather than creating a new h1 element.

In most cases, you'll probably want to generate a new h1 element instead. You can specify this by using the :fresh modifier:

p[style-name='Heading 1'] => h1:fresh

The two consecutive Heading 1 .docx paragraphs will then be converted to two separate h1 elements.

Reusing elements is useful in generating more complicated HTML structures. For instance, suppose your .docx contains asides. Each aside might have a heading and some body text, which should be contained within a single div.aside element. In this case, style mappings similar to p[style-name='Aside Heading'] => div.aside > h2:fresh and p[style-name='Aside Text'] => div.aside > p:fresh might be helpful.

Document element matchers

Paragraphs, runs and tables

Match any paragraph:

p tag

Match any run:

r tag

Match any table:

table tag

To match a paragraph, run or table with a specific style, you can reference the style by name. This is the style name that is displayed in Microsoft Word or LibreOffice. For instance, to match a paragraph with the style name Heading 1:

p[style-name='Heading 1']

You can also match a style name by prefix. For instance, to match a paragraph where the style name starts with Heading:

p[style-name^='Heading']

Styles can also be referenced by style ID. This is the ID used internally in the .docx file. To match a paragraph or run with a specific style ID, append a dot followed by the style ID. For instance, to match a paragraph with the style ID Heading1:

p.Heading1

Bold

Match explicitly bold text:

b tag

Note that this matches text that has had bold explicitly applied to it. It will not match any text that is bold because of its paragraph or run style.

Italic

Match explicitly italic text:

i tag

Note that this matches text that has had italic explicitly applied to it. It will not match any text that is italic because of its paragraph or run style.

Underline

Match explicitly underlined text:

u tag

Note that this matches text that has had underline explicitly applied to it. It will not match any text that is underlined because of its paragraph or run style.

Strikethough

Match explicitly struckthrough text:

strike tag

Note that this matches text that has had strikethrough explicitly applied to it. It will not match any text that is struckthrough because of its paragraph or run style.

All caps

Match explicitly all caps text:

all-caps

Note that this matches text that has had all caps explicitly applied to it. It will not match any text that is all caps because of its paragraph or run style.

Small caps

Match explicitly small caps text:

small-caps

Note that this matches text that has had small caps explicitly applied to it. It will not match any text that is small caps because of its paragraph or run style.

Ignoring document elements

Use ! to ignore a document element. For instance, to ignore any paragraph with the style Comment:

p[style-name='Comment'] => !

HTML paths

Single elements

The simplest HTML path is to specify a single element. For instance, to specify an h1 element:

h1 tag

To give an element a CSS class, append a dot followed by the name of the class:

h1.section-title

To require that an element is fresh, use :fresh:

h1:fresh

Modifiers must be used in the correct order:

h1.section-title:fresh

Separators

To specify a separator to place between the contents of paragraphs that are collapsed together, use :separator('SEPARATOR STRING').

For instance, suppose a document contains a block of code where each line of code is a paragraph with the style Code Block. We can write a style mapping to map such paragraphs to <pre> elements:

p[style-name='Code Block'] => pre

Since pre isn't marked as :fresh, consecutive pre elements will be collapsed together. However, this results in the code all being on one line. We can use :separator to insert a newline between each line of code:

p[style-name='Code Block'] => pre:separator('\n')

Nested elements

Use > to specify nested elements. For instance, to specify h2 within div.aside:

div.aside > h2

You can nest elements to any depth.

Subscribe to us

Subscribe to our daily newsletter to get the latest news.