HTML basics
HTML is the language used to describe the content and structure of a web page. This guide introduces tags, elements, attributes, and the document structure beginners need first.
What you will learn
- What HTML describes and how it differs from CSS and JavaScript
- How tags, elements, and attributes fit together
- How to structure a document with headings, paragraphs, and sections
What HTML does
HTML gives content meaning and structure: a heading is a heading, a paragraph is a paragraph, and a link is a link. CSS controls presentation, while JavaScript adds behavior.
Tags and elements
<p class="intro">Welcome to the web.</p>
The opening and closing tags surround the content, and together with that content they form an element. The class="intro" part is an attribute that adds information to the opening tag.
Document structure
<!doctype html>
<html lang="en">
<head>
<title>A page</title>
</head>
<body>
<h1>Page heading</h1>
<p>A paragraph.</p>
</body>
</html>
Elements can contain other elements, creating parent and child relationships. Keep the structure meaningful: headings should describe sections, and paragraphs should contain complete thoughts.
Special cases
- Empty elements: elements such as
imgandbrdo not wrap text content. - Comments:
<!-- note -->stays in the source and is not rendered as page content. - Validation: close elements correctly and use attributes appropriate to each element.