HTML Structure
Also HTML · CSS
HTML (Hypertext Markup Language) is the XML-like language that specifies the content of a web page as nested tagged elements, with meta information, style (CSS) and script includes in the head and the visible content in the body.
Formula#
Minimal valid page#
<html>
<head>
<meta charset="utf-8">
<style>/* CSS rules */</style>
<link rel="stylesheet" type="text/css" href="search.css"/>
<script src="script.js" defer></script>
</head>
<body>
<h1>Title</h1>
<p id="content">Text</p>
</body>
</html>
Key elements#
| Element | Purpose | Key attributes |
|---|---|---|
<h1> | level-1 heading | |
<p> | paragraph of text | id |
<div> | arbitrary “logical” section | id, class |
<input> | input field | id, type, name, value |
<button> | clickable button | |
<form> | groups inputs for submission (HTML Form) | method, action |
<a> | link | href |
<style> | inline CSS definitions | placed in <head> |
<link> | include a stylesheet | rel="stylesheet", href |
<script> | JavaScript, inline or from a file | src for external, defer |
<meta> | meta information | charset="utf-8" |
CSS#
CSS (Cascading Style Sheets) specifies style (layout, font, colour, …) independently of the content, in its own simple syntax selector { property: value; … }:
h1 { color: blue; font-weight: bold } /* all level-1 headings blue and bold */
#result { background: lightgray } /* the element with id "result" */
Cascading: when several rules apply to the same element, the most specific one wins. CSS goes into <style> in the head or into a separate file included with <link rel="stylesheet" …> (served with media type text/css).
Properties#
<head>contains metadata, styles and script references;<body>contains all visible content.- The
idattribute uniquely identifies an element for CSS selectors (#id) and JavaScript access (DOM Manipulation). - The
nameattribute on<input>determines the query parameter key when submitted via an HTML Form. - Script placement. Inline
<script>…</script>and<script src>withoutdeferare executed as soon as they are encountered. Withdefer, the script runs after the whole HTML has been parsed and the DOM constructed. A script in<head>withoutdefercannot find body elements; put it at the end of<body>or adddefer. <meta charset="utf-8">declares the Character Encoding of the page; if it does not match the bytes of the file, special characters are garbled (äinstead ofä).
Example#
Sources#
- Slides 09, pp. 15–16 (HTML), p. 17 (CSS)
- Slides 10, p. 9 (
<script>,defer), p. 31 (<meta charset>) - DBIS_VL09 > HTML, DBIS_VL09 > CSS, DBIS_VL10 > JavaScript as part of the HTML, DBIS_VL10 > URL encoding and decoding
- DBIS Exam WS1920 (not published) T3.1, DBIS Exam WS2122 (not published) T4.1, DBIS Exam WS2223 (not published) T4.2, DBIS Exam WS1617 (not published) T3.1