Reference article · Programming
Semantic HTML and page structure
HTML gives web content structure and meaning. CSS handles presentation and JavaScript can add behaviour. A useful page can start with a single HTML file without a framework.
Elements and attributes
Most elements have an opening tag, content and a closing tag. Attributes provide information: href supplies a link destination and lang declares a language. Void elements such as input have no closing tag.
A complete document
head holds metadata and the tab title; body holds visible content. Save this as index.html and open it in a browser. The viewport declaration helps mobile browsers use the device width.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My library</title>
</head>
<body>
<main>
<h1>Programming library</h1>
<p>Concepts and examples for learning.</p>
<a href="https://developer.mozilla.org/en-US/">Read MDN</a>
</main>
</body>
</html>Choose elements by purpose
main identifies primary content, nav groups navigation and article represents an independent composition. Headings h1 through h6 express hierarchy; use CSS to adjust their size. A div is a generic container when no specific meaning is needed.
Links, buttons and forms
Use links for navigation and buttons for actions. Native controls already provide keyboard behaviour. Associate each form field with a label using for and id; a placeholder does not replace a visible label.
<label for="name">Name</label> <input id="name" name="name" type="text"> <button type="button">Show greeting</button>
Practical review
- Use Tab to visit links and controls; check that focus is visible.
- Read only the headings and check the content order.
- Check that the tab title and language match the document.
References
Related articles
- Fundamentals: variables, conditions and loops
- CSS: box model, Flexbox and Grid
- JavaScript: functions, parameters and scope
- JavaScript: arrays, objects and data transformations
- DOM and events: connect JavaScript to HTML
- Promises, async/await and fetch requests
- HTTP and web APIs: requests, responses and status codes
- JSON: format, parsing and data validation
- Git: changes, commits, branches and remotes
- Node.js and npm: project scripts and dependencies
- Debugging and tests: finding and checking errors
- Colour formats: HEX, RGB and HSL
- UUID identifiers
- Random values in JavaScript
