Document skeleton
Every HTML page begins with a DOCTYPE declaration that tells the browser to use modern standards mode. The html element wraps the whole document and carries the lang attribute, such as lang="en", which tells screen readers and translation tools which language the text uses. Inside head you place metadata: the character set, a viewport declaration for small screens and exactly one title. The body holds everything a visitor actually sees. Setting up this skeleton before writing any content keeps later changes small and predictable.
Semantic regions
Semantic elements describe the role of a part of the page instead of only its box. The header holds the logo, main menu or search field; nav groups navigation links; main contains the unique central content of the page and should appear only once. An article is a self-contained piece such as a news story, a section groups content under a heading, aside holds related but separate notes, and footer carries copyright and contact details. A plain div or span is a neutral box that adds no meaning, so it belongs only to layout work.
Lists and tables
Use ol for ordered steps and ul for unordered groups; every item must sit inside an li element. Tables are meant for comparing data, not for arranging a page. Column headings use th with scope="col", and the body rows are grouped inside tbody. Screen readers announce the nearest heading as the column name while a user moves through a cell, which is why every table needs at least one header row. Wide tables should be wrapped in a scrollable container so they do not break the layout on phones.
Forms and labels
Each input needs a label, and the two must be linked. Give the input a unique id, such as email, and set the for attribute of the label to the same value. Clicking the label then moves the cursor into the field, and assistive technology reads the label aloud. The type attribute, for example type="email", lets the browser check the format, while required blocks an empty submission. The maxlength attribute only limits how many characters can be typed; it does not make a field mandatory, and mixing up the two is a frequent mistake.
Headings and accessibility
A page should have exactly one h1, which states its main subject, and heading levels should advance from h1 to h6 without skipping steps. Images need an alt attribute: a short, meaningful description for informative pictures and an empty alt="" for decorative ones. Interactive elements must be reachable with the keyboard, and text must have enough contrast against its background. These checks cost little when the page is built, but they are expensive to add after the design is finished.
Common mistakes
The most frequent error is building the whole page from div elements, which leaves screen readers and search engines without a map of the content. Another is placing several h1 elements or skipping heading levels just to change the font size; use CSS for size instead. Missing lang attributes, labels that are not connected to their fields, and tables used for layout are the next group of problems. Finally, a page with an unclosed tag or two title elements should be checked with a validator before it is published.
Frequently asked questions
Which semantic element holds the unique main content of a page?
The main element holds the unique, central content of a page, and it should appear only once. The header, nav, aside and footer elements mark supporting parts and do not replace main.
Which attribute makes a field mandatory?
The required attribute makes a field mandatory and stops an empty form from being sent by the browser. The maxlength attribute only limits the number of characters and does not force the user to fill the field.
When should I use div and span?
Use div and span only when an element has no semantic meaning and is needed purely for layout or styling. If a region carries meaning, such as navigation or a main article, a semantic tag is the correct choice.
Create an account — save your progress
Save your notes