<!doctype html>
Activates modern standards mode. Without it, browsers may use older compatibility behavior.
Write your first real HTML page: doctype, html, head, body, title, metadata, visible content, file paths, browser parsing and a live code lab.
HTML Basic
When people say “basic HTML”, they often mean the smallest page a browser can read correctly. That page still
has structure. It starts with a doctype, contains one root html element, has a
head for information about the page and a body for the visible content.
This matters because the browser does not guess your intention like a human does. It reads a document from top to bottom, builds a tree from the markup and then renders the result. A clean starting structure makes every next lesson easier: headings, paragraphs, links, images, CSS, JavaScript, SEO and accessibility.
Tell the browser to use modern standards mode.
The root element that wraps the complete document.
Metadata, title, character set, viewport and linked files.
The visible page: text, buttons, links, media and layout.
Document skeleton
The skeleton below is not decoration. Every line has a job. The doctype controls browser mode. The
lang attribute helps browsers, translation tools and assistive technology. The charset tells the
browser how to read characters. The viewport makes the page behave correctly on phones. The title appears in
browser tabs, bookmarks and search results.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>My first HTML page</title> </head> <body> <h1>Hello HTML</h1> <p>This is my first page.</p> </body> </html>
Line by line
A beginner often looks only at what appears on the screen. HTML has more than that. Some parts are meant for the browser, search engines and tools. Other parts are meant for the visitor. A good developer knows which is which.
<!doctype html>Activates modern standards mode. Without it, browsers may use older compatibility behavior.
<html lang="en">Wraps the document and tells tools the main language of the page.
<head>Contains page information that usually is not shown as visible content.
<meta charset>Defines the character encoding. Use UTF-8 for modern pages.
<meta viewport>Makes responsive layout possible on phones and tablets.
<body>Contains the content users can see and interact with.
Tag anatomy
HTML is built from elements. An element is usually made from an opening tag, content and a closing tag. The tag
name describes what the content is. A paragraph uses p. A heading uses h1 to
h6. A link uses a. The browser uses those names to understand the document.
<p>
This is a paragraph.
</p>
Some elements do not wrap text content. Examples are meta, img, br,
input and link. Those are often called void elements. You do not write
</img> or </meta> in modern HTML.
Basic attributes
The element name tells the browser what something is. Attributes add extra information. A link without
href does not know where to go. An image without src does not know what file to load.
An image without useful alt text is weaker for accessibility.
<a href="/html/elements/"> Learn HTML elements </a>
<img src="assets/img/editor.png" alt="Code editor showing HTML" >
Head versus body
The head is easy to misunderstand because most of it is not visible. But it is extremely
important. It controls the document title, character encoding, mobile viewport, CSS files, icons and metadata
that search engines or social platforms may use. The body is where the visible user interface
lives.
headmeta charsetmeta viewporttitlelink rel="stylesheet"bodyheader and navigationmain contentfooter contentFiles and paths
index.html.
The file name matters. A web server usually looks for index.html when someone opens a folder or
the root of a website. That is why the first page of a static website is commonly called index.html.
Keep related files in predictable folders so paths stay readable.
A simple but scalable structure for a first HTML project.
my-first-site/
index.html
assets/
css/
styles.css
js/
app.js
img/
logo.svg
If index.html links to assets/css/styles.css, the browser starts from the location of
the HTML file and follows that path. Many broken CSS and image problems are simply path problems.
How the browser reads it
When you open an HTML file, the browser does not just paint text on the screen. It parses the markup, creates the DOM, applies CSS, runs JavaScript and then renders pixels. The DOM is the live document tree. DevTools show this tree, which is why DevTools sometimes looks different from your raw source file.
The text file you wrote in the editor.
The browser reads tags, text and nesting.
A live structure CSS and JavaScript can work with.
The visual result users see and click.
Common mistakes
Browsers are forgiving, so broken HTML often still shows something. That can trick beginners into thinking the code is correct. Learn to spot the small mistakes early, because the same patterns become harder to debug when a project grows.
The browser may switch into older compatibility behavior.
The page can look wrong on phones even when the desktop version looks fine.
The browser may repair the DOM in a way you did not expect.
Metadata belongs in head, visible content belongs in body.
Images and CSS fail because the path does not match the folder structure.
Do not choose elements only because the browser default style looks nice.
Live code lab
Change the title text, heading, paragraph or list items. The preview updates live. The lab wraps your HTML in a full document so you can focus on the visible structure first, then compare it with the skeleton above.
Try it yourself
Checklist
The first line is <!doctype html>.
The html element has a useful lang attribute.
The document has charset, viewport and title in the head.
The body contains clear headings, paragraphs and sections.
Child elements are indented under their parent elements.
The file has been opened, refreshed and inspected in DevTools.
Next step
The basic page gives you the frame. The next lessons explain the pieces inside that frame. Start with HTML elements to learn the vocabulary, then move into attributes to understand how elements are configured.
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.