Introducing HTML
This is an introduction to the basics of HTML
Dr Graeme StuartThis is an introduction to the basics of HTML
Dr Graeme StuartMarkup refers to literally making marks on a written manuscript to indicate how it should be treated when printed.
Markup languages add information about the content.
Note that HTML does not include any information about how to format content. It simply indicates what kind of content the various parts of the document are.
An HTML document is composed of nested HTML elements containing text content. The tags imbue the content with meaning and default formatting in the browser.
|
|
This content is marked up using HTML to indicate that the first line is a level 2 heading and the rest of the text should be combined into one paragraph. Emphasis has been added to a few of the words.
HTML elements consist of content between matching pairs of tags.
The opening and closing tags are slightly different
Paragraphs are essential for structuring text. By default they have a margin top and bottom. This separates them from each other and from other content.
|
|
Lorem ipsum dolor sit amet. Ut, inventore voluptatibus? Molestiae, fugiat! Neque illum quas accusantium voluptates.
Notice how the text is merged and automatically laid out.
Headings come in six levels from
<h1>
to<h6>
. Headings provide accessibility landmarks for assistive technologies.
|
|
Headings should provide a navigable document structure. For most circumstances, six levels is too much.
Lists are collections of list items (
<li>
) which contain the actual content. List items are wrapped in containers that come in two main forms.
Unordered lists (<ul>
) generate bullet points and should be used when order doesn’t matter (e.g. ingredient list).
Ordered lists (<ol>
) generate numbered lists and should only be used when order matters (e.g recipe steps).
|
|
|
|
Using lists provide screen reader users with a much nicer experience. Even if the numbers or bullets are removed with styling.
Elements can have attributes to add information that should not be considered content. Attributes are key/value pairs separated by an equals symbol.
|
|
Attributes are placed inside the opening tag.Attribute values should be contained in “double quotes”. Pay attention to the details.
|
|
Some common mistakes include missing the space between attributes and missing quotes around attribute values.
Anchor elements require a hypertext reference (an href
attribute) pointing to the link destination as a Uniform Resource Locator (URL).
There are three main kinds of link.
linking to another element
|
|
linking to another document
|
|
linking to another server
|
|
Combinations are common.
|
|
The content will become a clickable link.
Clicking the link with induce the browser to issue an HTTP GET
request and render the document provided by the server.
Void elements such as
<br>
,<img>
and<input>
are not allowed to contain content. These elements do not require closing tags.
|
|
The
<input>
element has a value attribute rather than content.
|
|
The
<link>
and<meta>
elements are also void
The void
<img>
element includes asrc
attribute specifying the path to the source image file.
|
|
Images must include an
alt
(alternative text) attribute to show if the image cannot be loaded/presented. Thealt
attribute content will be announced by assistive technologies.
Semantic elements add meaning to your document structure and provide accessibility advantages. Choosing semantic elements in preference to meaningless elements such as
<div>
and<span>
adds meaning.
|
|
|
|
Semantic documents can be understood more fully by the browser and by other software because the various elements have been given meaning.
Accessible Rich Internet Applications (ARIA) present information to assistive technologies to improve accessibility. Adding a
role
will convert your element into an ARIA landmark.
|
|
|
|
Adding this extra information can be a pain. Luckily, we don’t need to. We can simply choose appropriate elements to create meaningful, accessible structure in our documents.
Most of the newer, semantic elements include these roles implicitly. This makes your HTML simpler and more accessible. See the Chrome A11y podcast for more on accessibility.
ALL HTML5 documents consist of a
<!DOCTYPE html>
and an<html>
element only. There should be nothing else in the file!
|
|
|
|
The
<html>
element should contains only a<head>
element and a<body>
element. Nothing else is allowed as a direct child of the<html>
element.
Within the
<head>
element there should be a<title>
element and<meta>
element defining the character set. You can also add other information about the document, including linked files and scripts. All the visible content of the page should be inside the<body>
element.
|
|
Validate your HTML!
<!doctype html>
and an <html>
element<head>
element contains information about the document<body>
element contains visible content<header>
, <main>
, <footer>
etc.Now take this into the lab.
If you have any questions, now is a good time to ask.
Thanks for listening
Dr Graeme Stuart