View the original version of this page!

Load



HTML


HTML (HyperText Markup Language) is a web language used to make web pages. HTML elements define the content of a web page. The tree of nested elements that make up a web page is called the Document Object Model.

An important property of elements is their display property. There are several ways an element could display on the page. This is often changed in CSS. Some possible values are:

  1. None - Does not display at all. Used to hide elements from CSS.
  2. Block - Will create a new line and expand horizontally as much as possible. Most block display elements cannot be nested, even if changed to inline with CSS. Elements such as span and div are considered grouping elements which can be nested. Setting display in CSS does not change this. (The HTML syntax is never altered by CSS.)
  3. Inline - Does not create a new line. Only takes as much space as needed and is part of the normal text flow.
  4. Flex - Makes the element a block-level flexible box (flexbox) container. A flexbox element will attempt to align and resize its contents across a set axis according to set parameters and proportions. The links at the top of this page are inside a flexbox container that aligns them horizontally with equal space between them. This property is set using CSS.
  5. Table, table-cell, table-column, table-row, etc. make the elements display as if they were in a table.

HTML elements, aside from their standard behaviour and CSS properties, have semantic meaning. The nav element, for example, is used for the navigation section (links to other pages). Even though this element is identical to a div in the browser, it is useful for other programs which are attempting to extract data from the web page, such as screen readers and search engines.

Most elements could be implemented using divs, spans, CSS and sometimes JavaScript, but it is better to use elements with the proper semantic meaning. Sometimes these elements have behaviour which cannot be completely replicated with JavaScript, but even when they don't it is important for code readability - if you see a "nav" element you immediately know what it is for, unlike a div with some CSS styling - and accessibility - screen readers often have to rely on semantic tags and the general structure of a web page to extract information from it. It is very hard for a program to parse a website which uses nonstandard "faked" elements, such as a div with a click handler which changes color when clicked instead of a button. This would not be recognised as an interactive element and would not be accessible by keyboard users either. Using HTML attributes such as tabindex="0", role="button", some of these issues can be resolved, however this will not support enter/space key presses, is unnecessarily complicated and therefore error-prone.

Note: The radio buttons work by assigning CSS classes with JavaScript.