What Is a .HTML File?

HTML document

📂Code
🏷️.html
🎯text/html

HTML Document (.html, .htm)

What is an HTML file?

An HTML (HyperText Markup Language) file is a standard markup language document used to create web pages. HTML files contain structured content using tags that define elements like headings, paragraphs, links, images, and other web page components. Web browsers interpret HTML files to display formatted web pages to users.

An HTML file is plain text. Nothing in it is compiled or encrypted, which is why the same file opens as a formatted page in a browser and as readable source in any text editor.

Technical Specifications

  • File Extensions: .html, .htm (the three-letter form dates from DOS filename limits; the two are identical)
  • MIME Type: text/html
  • Category: Code
  • Character Encoding: UTF-8 (recommended and the default in HTML5)
  • Created by: Tim Berners-Lee
  • Current Version: HTML Living Standard, maintained by the WHATWG
  • Related: XHTML (.xhtml, HTML expressed as strict XML), MHTML (.mht, a page and its assets in one file)

Recognising an HTML file

There is no binary signature. Detection relies on structure: a <!DOCTYPE html> declaration, an <html> root, <head> and <body> elements, or simply a density of angle-bracket tags. Some files are HTML without any extension at all (a downloaded page saved as index, an email body, a server response saved to disk), and some files named .html are really something else, such as a PHP template or an XML feed. Reading the content settles it.

More Information

HTML was created by Tim Berners-Lee in 1990 as part of the World Wide Web project at CERN. The first version of HTML was simple, but the language has evolved significantly over the years. HTML5, the current major version, was released in 2014 and includes many modern features for multimedia, graphics, and interactive content.

HTML serves as the foundation of the World Wide Web, providing the basic structure for virtually every website on the internet. It works alongside CSS (for styling) and JavaScript (for interactivity) to create modern web experiences.

HTML Structure

HTML documents follow a hierarchical structure with nested elements:

Basic Document Structure

  • DOCTYPE declaration: Specifies the HTML version
  • html element: Root element containing all content
  • head section: Metadata, title, links to resources
  • body section: Visible content of the web page

Common Elements

  • Headings: h1, h2, h3, h4, h5, h6 for document structure
  • Paragraphs: p for text blocks
  • Links: a for hyperlinks to other pages
  • Images: img for displaying pictures
  • Lists: ul, ol, li for organized content
  • Tables: table, tr, td for tabular data

A complete minimal document

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Title</title>
</head>
<body>
    <h1>Hello World</h1>
    <p>This is a paragraph.</p>
</body>
</html>

How to Open an HTML File

As a web page

  • Any browser (Chrome, Firefox, Edge, Safari): double-click the file, or drag it into an open window. The address bar shows a file:// path.
  • Windows: right-click, Open with, choose a browser. To change the default, go to Settings, Apps, Default apps, and pick a browser for .html.
  • macOS: double-click opens Safari by default; right-click, Open With for another browser. Use Get Info, Open with, Change All to set a permanent default.
  • Linux: xdg-open page.html opens the default browser from a terminal.
  • iPhone and Android: tapping an .html attachment usually opens it in the browser. Files from a cloud drive may open as a preview first; use Open in or Share to send it to Chrome or Safari.

As source code

  • Windows: Notepad, Notepad++, or VS Code. Right-click, Open with, Notepad.
  • macOS: TextEdit (choose Format, Make Plain Text first, or it may render the page instead of showing tags), or VS Code.
  • Linux: gedit, Kate, nano, vim.
  • In a browser: press Ctrl+U (Cmd+Option+U on Safari) on any open page to view its source.

Text/Code Editors

  • Visual Studio Code: Professional code editor with live preview extensions
  • Sublime Text: Lightweight text editor
  • Notepad++: Windows text editor
  • WebStorm: Professional IDE for web development

Why an HTML file looks wrong when opened locally

A page saved from the web often loses its images, styling or scripts when opened from disk. The usual causes:

  • Assets were not saved: "Save as, Webpage, HTML only" keeps the markup but none of the CSS, images or scripts. Use "Webpage, Complete" (which writes a folder beside the file) or "Webpage, Single File", which produces an MHTML archive.
  • Absolute links: the page references /css/site.css, which on your disk resolves to the root of your drive. The server that served the page is not there.
  • Scripts blocked on file://: browsers restrict what a local page may fetch. Serving the folder with a tiny local server fixes most of it:
# Python, any OS
python -m http.server 8000
# then open http://localhost:8000/page.html

# Node
npx serve .

How to Convert an HTML File

  • To PDF: open in any browser, Print, choose Save as PDF. From the command line, chrome --headless --print-to-pdf=out.pdf page.html.
  • To a Word document: Word opens .html directly (File, Open), then Save As .docx. Pandoc does it in one step: pandoc page.html -o page.docx.
  • To Markdown: pandoc page.html -t gfm -o page.md.
  • To plain text: lynx -dump page.html or html2text.
  • From Markdown or Word to HTML: pandoc notes.md -o notes.html; Word's Save As, Web Page, Filtered produces cleaner markup than the plain Web Page option.

How to Create HTML Files

HTML files can be created with any text editor. Save the file with a .html extension and UTF-8 encoding; on Windows, make sure Notepad does not append .txt.

Development Tools

  • Visual Studio Code: With live preview extensions
  • WebStorm: Professional IDE for web development
  • Online editors: CodePen, JSFiddle for quick testing
  • Validation: the W3C Markup Validation Service checks a page against the standard

Common Use Cases

  • Websites: All web pages use HTML as foundation
  • Email templates: HTML emails with rich formatting
  • Documentation: Technical documentation and help files
  • Landing pages: Marketing and promotional pages
  • Web applications: Single-page applications (SPAs)
  • Mobile apps: Hybrid apps using web technologies
  • Digital publications: Online magazines and books

Security Notes

An HTML file is a program as far as a browser is concerned: it can contain JavaScript. Opening an .html attachment from an unknown sender runs that script locally, which is why "HTML smuggling" is a common phishing technique, with the file drawing a fake login form or decoding a hidden payload. Treat an unexpected HTML attachment with the same suspicion as an executable, and view its source in a text editor rather than a browser if you need to inspect it.

Advantages

  • Universal support: Works in all web browsers
  • Easy to learn: Simple tag-based syntax
  • Semantic markup: Meaningful structure for content
  • Accessibility: Built-in support for screen readers
  • SEO friendly: Search engines understand HTML structure
  • Cross-platform: Works on all devices and operating systems
  • Free and open: No licensing fees or restrictions

HTML Best Practices

  • Use semantic elements: Choose tags based on meaning, not appearance
  • Validate markup: Ensure HTML follows standards
  • Include alt text: Describe images for accessibility
  • Optimize for mobile: Use responsive design principles
  • Keep it clean: Use consistent indentation and formatting
  • Separate concerns: Use CSS for styling, JavaScript for behavior
  • CSS: the stylesheet language HTML pages link to.
  • JAVASCRIPT: the scripting language that makes pages interactive.
  • MHT: a page and all its assets saved as one file.
  • XML: the stricter markup family XHTML belongs to.
  • MARKDOWN: the lightweight format most often converted to HTML.
  • PDF: the usual fixed-layout export target.

File Information

File Description

HTML document

Category

Code

Extensions

.html, .htm

MIME Type

text/html

Related File Types

Other file types in the Code category you might also need:

Related reading

Start Analyzing HTML Files Now

Use our free AI-powered tool to detect and analyze HTML document files instantly with Google's Magika technology.

⚡Try File Detection Tool