Basics Β· Astro Tech Blog

HTML

HTML (HyperText Markup Language) is the standard language for creating web pages. It describes the structure of a web page using a system of tags and attributes. Every website you visit is built on HTML.

History of HTML

HTML was created by Tim Berners-Lee in 1991 while working at CERN. He wanted a way for scientists to share documents over the internet. The first version had only 18 tags. Today, HTML has over 140 tags and is maintained by the W3C (World Wide Web Consortium) and WHATWG (Web Hypertext Application Technology Working Group).

HTML Versions Timeline

VersionYearKey Features
HTML 1.01991Basic text, links, images
HTML 2.01995Forms, tables
HTML 3.21997CSS support, scripts
HTML 4.011999Improved CSS, accessibility
XHTML 1.02000Stricter syntax (XML-based)
HTML52014Semantic tags, audio/video, canvas, local storage
HTML 5.12016Minor improvements
HTML 5.22017New features and fixes

The current standard is HTML5, which added semantic elements like <header>, <footer>, <article>, and native multimedia support.

How Browser Render HTML

When you visit a webpage, the browser goes through these steps:

  1. Parse HTML β€” reads the HTML file and builds a DOM (Document Object Model) tree.
  2. Load CSS β€” applies styles to the DOM elements.
  3. Execute JavaScript β€” runs scripts that may modify the DOM.
  4. Render β€” paints the visual output on your screen.
HTML File  β†’  Parser  β†’  DOM Tree  β†’  Render Tree  β†’  Display
    ↓
External resources (CSS, JS, images) loaded in parallel

HTML Document Structure

Every HTML document follows a basic structure:

Demo: HTML Document Structure
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first HTML page.</p>
</body>
</html>
Live Output Window

Type Declaration

<!DOCTYPE html> tells the browser that this is an HTML5 document. It must be the very first line in any HTML file.

html Element

The <html> element is the root of every HTML page. All other elements go inside it. The lang attribute (e.g., lang="en") tells the browser the page language β€” important for accessibility and SEO.

head Element

The <head> element contains metadata β€” information about the page that is not displayed directly. This includes the page title, character encoding, links to CSS files, and meta tags for SEO.

body Element

The <body> element contains everything visible on the page β€” headings, paragraphs, images, links, forms, and all other content.

Tags

HTML uses tags to mark up content. Tags are words wrapped in angle brackets:

HTML
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Live Output Window

Most tags come in pairs: an opening tag (<h1>) and a closing tag (</h1>). Some tags are self-closing (void elements):

HTML
<br>    <!-- line break -->
<img>   <!-- image -->
<input> <!-- input field -->
Live Output Window

Elements

An element is everything from the opening tag to the closing tag, including the content:

<tag>     content     </tag>
β””β”€β”¬β”€β”˜   β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β””β”€β”€β”¬β”€β”€β”˜
opening   content     closing
tag       between     tag

Example:

HTML
<p>This is a paragraph element.</p>
Live Output Window

The element includes the <p> tag, the text β€œThis is a paragraph element.”, and the </p> tag.

Tags vs Elements

TagsElements
The markup itself (<p>, </p>)Tags + content together
Used to define where an element starts/endsThe complete unit rendered by the browser
<a href="..."> is a tag<a href="...">Click me</a> is an element

Think of tags as the wrapper and elements as the wrapped package.

Attributes

Attributes provide additional information about an element. They go inside the opening tag:

HTML
<a href="https://example.com" target="_blank">Visit Example</a>
Live Output Window

Attributes are written as name="value" pairs:

AttributePurpose
hrefURL for links
srcSource file for images
altAlternative text for images
classCSS class name
idUnique identifier
styleInline CSS
targetWhere to open a link

Common patterns:

<img src="photo.jpg" alt="A scenic view">
<input type="text" placeholder="Enter your name" required>
<div class="container" id="main-content">

HTML is case insensitive

HTML tags and attributes are case-insensitive β€” <P> and <p> both work. However, the convention is to use lowercase for all tags and attributes:

HTML
html
<!-- Correct convention -->
<p>Hello</p>
<a href="page.html">Link</a>

<!-- Works but not recommended -->
<P>Hello</P>
<A HREF="page.html">Link</A>
Live Output Window

Why use lowercase? Consistency, readability, and because XHTML (a stricter version) requires lowercase.

White spaces in HTML

In HTML, multiple spaces, tabs, and newlines are collapsed into a single space:

HTML
<p>This     text
has        many
spaces</p>
Live Output Window

Renders as: This text has many spaces

To preserve whitespace, use the <pre> tag or CSS white-space: pre:

HTML
<pre>
This   text   preserves
all    spaces
and   line breaks
</pre>
Live Output Window

To add a single extra space, use the &nbsp; entity (non-breaking space):

HTML
<p>Hello Β  World</p>
Live Output Window

HTML Comments

Comments are ignored by the browser and are only visible in the source code. Use <!-- -->:

HTML
<!-- This is a comment β€” it won't be displayed -->
<p>Visible content</p>

<!--
Multi-line
comment
-->
Live Output Window

Comments are useful for:

  • Explaining sections of code
  • Temporarily disabling code
  • Leaving notes for yourself or other developers