HTML

Topics related to HTML:

Getting started with HTML

HTML (Hypertext Markup Language) is an XML-compliant system of annotating documents with 'tags'. It is used specifically to create content for web pages and web applications, which can then be shared over a network.

Apart from text, the current version of HTML supports many different types of media, including images and videos.

Headings

  • An h1h6 element must have both a start tag and an end tag.1

  • h1h6 elements are block level elements by default (CSS style: display: block).2

  • h1h6 elements should not be confused with the section element

  • Heading tags (h1h6) are not related to the head tag.

  • Permitted Content: phrasing content

  • The different CSS-styles for headings differ usually in font-size and margin. The following CSS-settings for h1h6 elements can serve as an orientation (characterized as 'informative' by the W3C)

  • Search engine spiders (the code that adds a page to a search engine) automatically pays more attention to higher importance (h1 has most, h2 has less, h3 has even less, ...) headings to discern what a page is about.

Anchors and Hyperlinks

Tables

The various table elements and their content attributes together define the table model. The <table> element is the container element for table models/tabular data. Tables have rows, columns, and cells given by their descendants. The rows and columns form a grid; a table's cells must completely cover that grid without overlap. The list below describes the various elements in the table model:

  • <table> - The container element for table models/tabular data. <table> represents data with more than one dimension in the form of a table.
  • <caption> - Table caption or title (Like a figcaption to a figure)
  • <col> - A column (a no-content element)
  • <colgroup> - A grouping of columns
  • <thead> - Table header (only one)
  • <tbody> - Table body / content (multiple are okay)
  • <tfoot> - Table footer (only one)
  • <tr> - Table row
  • <th> - Table header cell
  • <td> - Table data cell

Semantically, tables are meant for holding tabular data. You can think of it as a way to display and describe data that would make sense in a spreadsheet (columns and rows).

Using tables for layout is not recommended. Instead, use CSS rules for layout and formatting, including display: table.

One notable exception typically displayed in the industry regarding using <table> layout is in regards to HTML email: some email clients, including Outlook, rolled back to older rendering engines after Microsoft lose their monopoly case vs. the EU. In order for Microsoft to make IE not part of the OS, they simply rolled back Outlook's rendering engine to an earlier version of Trident. This rollback simply doesn't support modern web technologies, so using <table> based layouts for HTML email is the only way to ensure cross-browser/platform/client compatibility.

Input Control Elements

As with other HTML5 void elements, <input> is self-closing and may be written <input />. HTML5 does not require this slash.

The following are valid input types in HTML:

5

The following are newly introduced input types as a part of HTML 5 standard. Some of these types are not supported by all web browsers. In the case where a type is not supported, the input element will default to the text type.

To check which browsers support which types, you can go to caniuse.com.

Sectioning Elements

The HTML5 standards does not list the main element as a sectioning element.

Lists

See Also

You can add a list-style-type CSS property to an <ul> tag in order to change what kind of icon is used to mark each list item, for example <ul style="list-style-type:disc">. The following list-style-types are permitted:

  • "list-style-type:disc" is the default dot.
  • "list-style-type:circle" is an unfilled circle.
  • "list-style-type:square" is a filled square.
  • "list-style-type:none" uses no mark at all.

You can also add a type attribute to an <ol> tag in order to change how numbering is done, for example <ol type="1">. The following types are permitted:

  • type="1" is the default form.
  • type="A" uses uppercase letters in alphabetical order
  • type="a" uses lowercase letters in alphabetical order
  • type="I" uses roman numerals with uppercase lettering
  • type="i" uses roman numerals with lowercase lettering

Comments

Anything starting with <!-- and ending with --> is a comment. Comments cannot contain two adjacent dashes (--), and must end with exactly two dashes (i.e. ---> is not correct).

Comments are not visible on a web page and cannot be styled with CSS. They can be used by the page's developer to make notes within the HTML, or to hide certain content during development.

For dynamic or interactive pages, hiding and showing content is done with JavaScript and CSS rather than with HTML comments.

JavaScript can be used to get the content of HTML comment nodes and these nodes can be dynamically created, added and removed from the document but this will not affect how the page is displayed.

Since HTML comments are part of the page's source code, they are downloaded to the browser along with the rest of the page. The source code can typically be viewed using the web browser's menu option to "View Source" or "View Page Source."

IFrames

An iframe is used to embed another document in the current HTML document.

You CAN use iframes for displaying:

You SHOULD use an iframe as a last resort, as it has problems with bookmarking and navigation, and there are always better options other than an iframe. This SO question should help you understand more about the ups and downs of iframes.


Same-origin policy

Some sites cannot be displayed using an iframe, because they enforce a policy called Same-origin policy. This means that the site that the iframe lies on must be on the same domain as the one to be displayed.

This policy also applies to manipulating content that lives inside of an iFrame. If the iFrame is accessing content from a different domain, you will not be able to access or manipulate the content inside of an iFrame.

The iframe element on W3C


sandbox attribute

The sandbox attribute, when set, adds extra restrictions to the iframe. A space separated list of tokens can be used to relax these restrictions.

ValueDetails
allow-formsAllows forms to be submitted.
allow-pointer-lockEnables the JavaScript pointer API.
allow-popupsPopups can be created using window.open or <a target="_blank"
allow-same-originThe iframe document uses its real origin instead of being given a unique one. If used with allow-scripts the iframe document can remove all sandboxing if it's from the same origin as the parent document.
allow-scriptsEnables scripts. The iframe document and parent document may be able to communicate with each other using the postMessage() API. If used with allow-same-origin the iframe document can remove all sandboxing if it's from the same origin as the parent document.
allow-top-navigationAllows the iframe's content to change the location of the top level document.

Text Formatting

Classes and IDs

  • Both class and id are global attributes, and may therefore be assigned to any HTML element.
  • Class names must begin with a letter (A-Z or a-z) and can be followed by letters, digits , hyphens and underscores.
  • In HTML5, the class and id attributes can be used on any element. In HTML 4.0.1, they were off-limits to the <base>, <head>, <html>, <meta>, <param>, <script>, <style> and <title> tags.
  • An element can have one or more classes. Classes are separated by spaces and cannot contain spaces themselves.
  • An element can have only one ID and it must be unique within its context (i.e. a webpage). IDs also cannot contain spaces themselves.

Images

Linking Resources

Selection Menu Controls

Output Element

Content Languages

Doctypes

Forms

The <form> element represents a section that contains form-associated elements (e.g. <button> <fieldset> <input> <label> <output> <select> <textarea>) that submits information to a server. Both starting (<form>) and ending (</form>) tags are required.

Canvas

Data Attributes

SVG

Meta Information

Void Elements

A void element cannot have any content but may have attributes. Void elements are self-closing, so they must not have a closing tag.

In HTML5, the following elements are void:

  • area
  • base
  • br
  • col
  • embed
  • hr
  • img
  • input
  • keygen
  • link
  • meta
  • param
  • source
  • track
  • wbr

Div Element

Label Element

Marking up computer code

The code element should be used for any kind of "string that a computer would recognize" (HTML5), for example:

  • source code
  • terms from markup/programming languages (element names, function names, etc.)
  • file names

Related elements

For variables, the var element can be used.

For computer output, the samp element can be used.

For user input, the kbd element can be used.

Media Elements

Support in browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support3.03.5 (1.9.1)9.010.503.1
<audio>: PCM in WAVE(Yes)3.5 (1.9.1)No support10.503.1
<audio>: Vorbis in WebM(Yes)4.0 (2.0)No support10.603.1
<audio>: Streaming Vorbis/Opus in WebM via MSE?36.0???
<audio>: Vorbis in Ogg(Yes)3.5 (1.9.1)No support10.50No support
<audio>: MP3(Yes)(Yes)9.0(Yes)3.1
<audio>: MP3 in MP4????(Yes)
<audio>: AAC in MP4(Yes)(Yes)9.0(Yes)3.1
<audio>: Opus in Ogg27.015.0 (15.0)???
<video>: VP8 and Vorbis in WebM6.04.0 (2.0)9.010.603.1
<video>: VP9 and Opus in WebM29.028.0 (28.0)?(Yes)?
<video>: Streaming WebM via MSE?42.0 (42.0)???
<video>: Theora and Vorbis in Ogg(Yes)3.5 (1.9.1)No support10.50No support
<video>: H.264 and MP3 in MP4(Yes)(Yes)9.0(Yes)(Yes)
<video>: H.264 and AAC in MP4(Yes)(Yes)9.0(Yes)3.1
any other formatNo supportNo supportNo supportNo support3.1

Tabindex

The maximum value for tabindex should not exceed 32767 as per W3C section 17.11.1 Unless specified default value is -1

An element with a value of 0, an invalid value, or no tabindex value should be placed after the elements with a positive index in the sequential order of keyboard navigation.

ARIA

ARIA is a specification for semantically describing rich web applications. Following ARIA standards can increase accessibility for those using assistive technologies (such as a screen reader) to access your content.

Global Attributes

Global attributes are simply attributed which can be applied to any element in the entire document.

Marking-up Quotes

cite and blockquote elements should not be used for the purpose of representing a conversation, transcripts of conversations, dialogues in scripts, records of instant messages and other situations in which different players take turns in the speech.

Include JavaScript Code in HTML

If the embed JavaScript code (file) is used to manipulate http://stackoverflow.com/documentation/javascript/503/document-object-model-dom Elements, place your <script></script> tags right before the closing </body> tag or use JavaScript methods or libraries (such as jQuery to handle a variety of browsers) that makes sure the DOM is read and ready to be manipulated.

Image Maps

Using HTML with CSS

Progress Element

The <progress> element is not supported in versions of Internet Explorer less than 10

The <progress> element is the wrong element to be used for something that is just a gauge, rather than the task progress. For example, showing the usage of disk space by using the <progress> element is inappropriate. Instead, the <meter> element is available for this type of use cases.

Character Entities

Paragraphs

HTML 5 Cache

The manifest file is a simple text file, which tells the browser what to cache (and what to never cache). The recommended file extension for manifest files is: ".appcache" The manifest file has three sections:

CACHE MANIFEST - Files listed under this header will be cached after they are downloaded for the first time

NETWORK - Files listed under this header require a connection to the server, and will never be cached

FALLBACK - Files listed under this header specifies fallback pages if a page is inaccessible

Embed

Navigation Bars

HTML Event Attributes