HTML: reference
Page markup: structure, text, lists, tables and forms.
Page structure
Document template
Everything the user sees is inside body. The head holds service information.
<!DOCTYPE html> <html lang="uk"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Page title</title> </head> <body> <h1>Hello, world!</h1> </body> </html>
Comments
Elements are written as tags: an opening <p> and a closing </p>.
<!-- this text is not displayed -->
Text
Headings and paragraphs
There should be one h1 on the page. The tags br (line break) and hr (line) have no closing tag.
<h1>Main heading</h1> <h2>Subheading</h2> <p>A paragraph of text with <strong>important</strong> and <em>emphasised</em> words.</p> <br> <hr>
Other text tags
Choose a tag by its meaning, not by its looks: CSS takes care of the styling.
<blockquote>A quotation</blockquote> <pre>Text with spaces preserved</pre> <code>console.log(1)</code> <mark>marked</mark> <small>small print</small>
Links and images
Links
For target="_blank" add rel="noopener".
<a href="https://example.com">External</a> <a href="about.html">Another page</a> <a href="#contacts">To a section on the page</a> <a href="https://example.com" target="_blank" rel="noopener">In a new tab</a>
Images
The alt attribute is required: screen readers read it and users see it when the image fails to load.
<img src="photo.jpg" alt="Image description" width="300">
Lists
Bulleted and numbered
ul is a bulleted list, ol is numbered. Items are always in li.
<ul> <li>Bread</li> <li>Milk</li> </ul> <ol> <li>First step</li> <li>Second step</li> </ol>
Tables
A simple table
tr is a row, th is a header cell, td is an ordinary cell. Do not use tables for page layout.
<table>
<thead>
<tr><th>Name</th><th>Age</th></tr>
</thead>
<tbody>
<tr><td>Alex</td><td>16</td></tr>
<tr><td>Ivan</td><td>17</td></tr>
</tbody>
</table>Forms
Input fields
Every field has a label linked through for and id. The required attribute makes a field mandatory.
<form action="/send" method="post"> <label for="name">Name</label> <input type="text" id="name" name="name" required> <label for="email">Email</label> <input type="email" id="email" name="email"> <textarea name="msg" rows="3"></textarea> <button type="submit">Send</button> </form>
Choices and checkboxes
Radio buttons with the same name form a group in which one option is chosen.
<select name="city"> <option value="dnipro">Dnipro</option> <option value="kyiv">Kyiv</option> </select> <input type="checkbox" name="agree" id="agree"> <input type="radio" name="level" value="1"> Beginner <input type="radio" name="level" value="2"> Intermediate
Semantic markup
Structural tags
Semantic tags help search engines and people understand the page structure.
<header>Site header</header> <nav><a href="/">Home</a></nav> <main> <article>Article</article> <aside>Sidebar</aside> </main> <footer>Footer</footer>
div and span
div takes the whole line, span sits inside the text. Neither has any meaning of its own.
<div class="card">Block container</div> <p>Text with <span class="accent">highlighting</span>.</p>
Multimedia and linking
Audio and video
The controls attribute shows the control buttons.
<video src="clip.mp4" controls width="400"></video> <audio src="song.mp3" controls></audio>
CSS and scripts
Styles are linked in head, and a script with defer runs after the page is parsed.
<link rel="stylesheet" href="style.css"> <script src="app.js" defer></script>
Learn HTML with practice
- 30 lessons, 23 of them base
- Tasks with in-browser code checking
- 3 projects from a specification, each requirement checked
- Free, nothing to install
Nearby in «Web technologies»: CSS · JavaScript · TypeScript