Structure
Even well-formed HTML pages are harder to process than they should be because of the lack of structure. You have to figure out where the section breaks go by analyzing header levels. Sidebars, footers, headers, navigation menus, main content sections, and individual stories are marked up by the catch-alldiv element. HTML 5 adds new elements to specifically identify each of these common constructs:section: A part or chapter in a book, a section in a chapter, or essentially anything that has its own heading in HTML 4header: The page header shown on the page; not the same as theheadelementfooter: The page footer where the fine print goes; the signature in an e-mail messagenav: A collection of links to other pagesarticle: An independent entry in a blog, magazine, compendium, and so forth
New Elements in HTML5
The following elements have been introduced for better structure:sectionrepresents a generic document or application section. It can be used together with theh1,h2,h3,h4,h5, andh6elements to indicate the document structure.articlerepresents an independent piece of content of a document, such as a blog entry or newspaper article.maincan be used as a container for the dominant contents of another element, such as the main content of the page. In W3C HTML5 and W3C HTML 5.1, only one such element is allowed in a document.asiderepresents a piece of content that is only slightly related to the rest of the page.- In WHATWG HTML,
hgrouprepresents the header of a section. headerrepresents a group of introductory or navigational aids.footerrepresents a footer for a section and can contain information about the author, copyright information, etc.navrepresents a section of the document intended for navigation.figurerepresents a piece of self-contained flow content, typically referenced as a single unit from the main flow of the document.<figure> <video src="example.webm" controls></video> <figcaption>Example</figcaption> </figure>
figcaptioncan be used as caption (it is optional).
videoandaudiofor multimedia content. Both provide an API so application Web developers can script their own user interface, but there is also a way to trigger a user interface provided by the user agent.sourceelements are used together with these elements if there are multiple streams available of different types.trackprovides text tracks for thevideoelement.embedis used for plugin content.markrepresents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context.progressrepresents a completion of a task, such as downloading or when performing a series of expensive operations.meterrepresents a measurement, such as disk usage.timerepresents a date and/or time.- WHATWG HTML and W3C HTML5.1 has
data, which allows content to be annotated with a machine-readable value. dialogfor showing a dialog.ruby,rt, andrpallow for marking up ruby annotations.bdirepresents a span of text that is to be isolated from its surroundings for the purposes of bidirectional text formatting.wbrrepresents a line break opportunity.canvasis used for rendering dynamic bitmap graphics on the fly, such as graphs or games.menuitemrepresents a command the user can invoke from a popup menu.detailsrepresents additional information or controls which the user can obtain on demand. Thesummaryelement provides its summary, legend, or caption.datalisttogether with the a newlistattribute forinputcan be used to make comboboxes:<input list="browsers"> <datalist id="browsers"> <option value="Safari"> <option value="Internet Explorer"> <option value="Opera"> <option value="Firefox"> </datalist>
keygenrepresents control for key pair generation.outputrepresents some type of output, such as from a calculation done through scripting.
input element’s type attribute now has the following new values:The idea of these new types is that the user agent can provide the user interface, such as a calendar date picker or integration with the user’s address book, and submit a defined format to the server. It gives the user a better experience as his input is checked before sending it to the server meaning there is less time to wait for feedback.
New Attributes
Several attributes have been introduced to various elements that were already part of HTML4:- The
aandareaelements have the newdownloadattribute in WHATWG HTML and W3C HTML5.1. WHATWG HTML also has thepingattribute. - The
areaelement, for consistency with theaandlinkelements, now also has thehreflang,typeandrelattributes. - The
baseelement can now have atargetattribute as well, mainly for consistency with theaelement. (This is already widely supported.) - The
metaelement has acharsetattribute now as this was already widely supported and provides a nice way to specify the character encoding for the document. - In WHATWG HTML and W3C HTML5.1, the
tableelement now has asortableattribute and thethelement has asortedattribute, which provide a means to sort table columns. - A new
autofocusattribute can be specified on theinput(except when thetypeattribute ishidden),select,textareaandbuttonelements. It provides a declarative way to focus a form control during page load. Using this feature should enhance the user experience compared to focusing the element with script as the user can turn it off if the user does not like it, for instance. - A new
placeholderattribute can be specified on theinputandtextareaelements. It represents a hint intended to aid the user with data entry.<input type=email placeholder="a@b.com">
- The new
formattribute forinput,output,select,textarea,button,label,objectandfieldsetelements allows for controls to be associated with a form. These elements can now be placed anywhere on a page, not just as descendants of theformelement, and still be associated with aform.<table> <tr> <th>Key <th>Value <th>Action <tr> <td><form id=1><input name=1-key></form> <td><input form=1 name=1-value> <td><button form=1 name=1-action value=save>✓</button> <button form=1 name=1-action value=delete>✗</button> ... </table> - The new
requiredattribute applies toinput(except when thetypeattribute ishidden,imageor some button type such assubmit),selectandtextarea. It indicates that the user has to fill in a value in order to submit the form. Forselect, the firstoptionelement has to be a placeholder with an empty value.<label>Color: <select name=color required> <option value="">Choose one <option>Red <option>Green <option>Blue </select></label>
- The
fieldsetelement now allows thedisabledattribute which disables all descendant controls (excluding those that are descendants of thelegendelement) when specified, and thenameattribute which can be used for script access. - The
inputelement has several new attributes to specify constraints:autocomplete,min,max,multiple,patternandstep. As mentioned before it also has a newlistattribute which can be used together with thedatalistelement. It also now has thewidthandheightattributes to specify the dimensions of the image when usingtype=image. - The
inputandtextareaelements have a new attribute nameddirnamethat causes the directionality of the control as set by the user to be submitted as well. - The
textareaelement also has two new attributes,maxlengthandwrapwhich control max input length and submitted line wrapping behavior, respectively. - The
formelement has anovalidateattribute that can be used to disable form validation submission (i.e. the form can always be submitted). - The
inputandbuttonelements haveformaction,formenctype,formmethod,formnovalidate, andformtargetas new attributes. If present, they override theaction,enctype,method,novalidate, andtargetattributes on theformelement. - In WHATWG HTML and W3C HTML5.1, the
inputandtextareahave aninputmodeattribute. - The
menuelement has two new attributes:typeandlabel. They allow the element to transform into a menu as found in typical user interfaces as well as providing for context menus in conjunction with the globalcontextmenuattribute. - In WHATWG HTML and W3C HTML5.1, the
buttonelement has a newmenuattribute, used together with popup menus. - The
styleelement has a newscopedattribute which can be used to enable scoped style sheets. Style rules within such astyleelement only apply to the local tree. - The
scriptelement has a new attribute calledasyncthat influences script loading and execution. - The
htmlelement has a new attribute calledmanifestthat points to an application cache manifest used in conjunction with the API for offline Web applications. - The
linkelement has a new attribute calledsizes. It can be used in conjunction with theiconrelationship (set through therelattribute; can be used for e.g. favicons) to indicate the size of the referenced icon, thus allowing for icons of distinct dimensions. - The
olelement has a new attribute calledreversed. When present, it indicates that the list order is descending. - The
iframeelement has three new attributes calledsandbox,seamless, andsrcdocwhich allow for sandboxing content, e.g. blog comments. - The
objectelement has a new attribute calledtypemustmatchwhich allows safer embedding of external resources. - The
imgelement has a new attribute calledcrossoriginto use CORS in the fetch and if it is successful, allows the image data to be read with thecanvasAPI. In WHATWG HTML and W3C HTML5.1, thescriptelement has acrossoriginattribute to allow script errors to be reported toonerrorwith information about the error. WHATWG HTML and W3C HTML5.1 also has thecrossoriginattribute on thelinkelement. - In WHATWG HTML, the
imgelement has a new attribute calledsrcsetto support multiple images for different resolutions and different images for different viewport sizes.
accesskey, class, dir, id, lang, style, tabindex and title. Additionally, XHTML 1.0 only allowed xml:space on some elements, which is now allowed on all elements in XHTML documents.There are also several new global attributes:
- The
contenteditableattribute indicates that the element is an editable area. The user can change the contents of the element and manipulate the markup. - The
contextmenuattribute can be used to point to a context menu provided by the Web developer. - The
data-*collection of Web developer-defined attributes. Web developers can define any attribute they want as long as they prefix it withdata-to avoid clashes with future versions of HTML. These are intended to be used to store custom data to be consumed by the Web page or application itself. They are not intended for data to be consumed by other parties (e.g. user agents). - The
draggableanddropzoneattributes can be used together with the new drag & drop API. - The
hiddenattribute indicates that an element is not yet, or is no longer, relevant. - WHATWG HTML and W3C HTML5.1 has the
inertattribute, intended to makedialogelements modal. - The
roleandaria-*collection attributes which can be used to instruct assistive technology. These attributes have slightly different requirements in WHATWG HTML and W3C HTML5/W3C HTML5.1. - The
spellcheckattribute allows for hinting whether content can be checked for spelling or not. - The
translateattribute gives a hint to translators whether the content should be translated.
onevent, global attributes and adds several new event handler attributes for new events it defines; for instance, the onplay event handler attribute for the play event which is used by the API for the media elements (video and audio).Content Model
The content model is what defines how elements may be nested — what is allowed as children (or descendants) of a certain element.At a high level, HTML4 had two major categories of elements, “inline” (e.g.
span, img, text), and “block-level” (e.g. div, hr, table). Some elements did not fit in either category.Some elements allowed “inline” elements (e.g.
p), some allowed “block-level” elements (e.g. body), some allowed both (e.g. div), while other elements did not allow either category but only allowed other specific elements (e.g. dl, table), or did not allow any children at all (e.g. link, img, hr).Notice the difference between an element itself being in a certain category, and having a content model of a certain category; for instance, the
p element is itself a “block-level” element, but has a content model of “inline”.To make it more confusing, HTML4 had different content model rules in its Strict, Transitional and Frameset flavors; for instance, in Strict, the
body element allowed only “block-level” elements, but in Transitional, it allowed both “inline” and “block-level”.To make things more confusing still, CSS uses the terms “block-level element” and “inline-level element” for its visual formatting model, which is related to CSS’s ‘display’ property and has nothing to do with HTML’s content model rules.
HTML does not use the terms “block-level” or “inline” as part of its content model rules, to reduce confusion with CSS. However, it has more categories than HTML4, and an element can be part of none of them, one of them, or several of them.
- Metadata content, e.g.
link,script. - Flow content, e.g.
span,div, text. This is roughly like HTML4’s “block-level” and “inline” together. - Sectioning content, e.g.
aside,section. - Heading content, e.g.
h1. - Phrasing content, e.g.
span,img, text. This is roughly like HTML4’s “inline”. Elements that are phrasing content are also flow content. - Embedded content, e.g.
img,iframe,svg. - Interactive content, e.g.
a,button,label. Interactive content is not allowed to be nested.
body element now allows flow content. Thus, This is closer to HTML4 Transitional than HTML4 Strict.Further changes include:
- The
addresselement now allows flow content, but with no heading content descendants, no sectioning content descendants, and noheader,footer, oraddresselement descendants. - HTML4 allowed
objectinhead. HTML does not. - WHATWG HTML allows
linkandmetaas descendants ofbodyif they use microdata attributes. - The
noscriptelement was a “block-level” element in HTML4, but is phrasing content in HTML. - The
table,thead,tbody,tfoot,tr,ol,ulanddlelements are allowed to be empty in HTML. - Table elements have to conform to the table model (e.g. two cells are not allowed to overlap).
- The
tableelement now does not allowcolelements as direct children. However, the HTML parser implies acolgroupelement, so this change should not affecttext/htmlcontent. - The
tableelement now allows thetfootelement to be the last child. - The
captionelement now allows flow content, but with no descendanttableelements. - The
thelement now allows flow content, but with noheader,footer, sectioning content, or heading content descendants. - The
aelement now has a transparent content model (except it does not allow interactive content descendants), meaning that it has the same content model as its parent. This means that theaelement can now contain e.g.divelements, if its parent allows flow content. - The
insanddelelements also have a transparent content model. HTML4 had similar rules in prose that could not be expressed in the DTD. - The
objectelement also has a transparent content model, after itsparamchildren. - The
mapelement also has a transparent content model. Theareaelement is considered phrasing content if there is amapelement ancestor, which means that they do not need to be direct children ofmap. - The
fieldsetelement no longer requires alegendchild.
New APIs
HTML introduces a number of APIs that help in creating Web applications. These can be used together with the new elements introduced for applications:- Media elements (
videoandaudio) have APIs for controlling playback, syncronising multiple media elements, and timed text tracks (e.g. subtitles). - An API for form constraint validation (e.g. the
setCustomValidity()method). - An API for commands that the user can invoke.
- An API that enables offline Web applications, with an application cache.
- An API that allows a Web application to register itself for certain protocols or media types, using
registerProtocolHandler()andregisterContentHandler(). - Editing API in combination with a new global
contenteditableattribute. - Drag & drop API in combination with a
draggableattribute. - An API that exposes the components of the document’s URL and allows scripts to navigate, redirect and reload (the
Locationinterface). - An API that exposes the session history and allows scripts to update
the document’s URL without actually navigating, so that applications
don’t need to abuse the fragment component for “Ajax-style” navigation
(the
Historyinterface). - An API for base64 conversion (
atob()andbtoa()methods). - An API to schedule timer-based callbacks (
setTimeout()andsetInterval()). - An API to prompt the user (
alert(),confirm(),prompt(),showModalDialog()). - An API for printing the document (
print()). - An API for handling search providers (
AddSearchProvider()andIsSearchProviderInstalled()). - The
Windowobject has been defined.
- An API for microdata.
- An API for immediate-mode bitmap graphics (the
2dcontext for thecanvaselement). - An API for cross-document messaging and channel messaging (
postMessage()andMessageChannel). - An API for runnings scripts in the background (
WorkerandSharedWorker). - An API for client-side storage (
localStorageandsessionStorage). - An API for bidirectional client-server communication (
WebSocket). - An API for server-to-client data push (
EventSource).
Comments
Post a Comment