Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1
Lesson 1: Introducing HTML5 CHAPTER 2 37

HTML5 global attribute reference
HTML5 defines a set of named attributes that can be applied to any HTML5 element. These
elements are called global attributes, and each has a very specific meaning, as follows.
■■accesskey Enables you to either specify a shortcut key to which to jump or to set
focus to an element. As a rule, you shouldn’t use this because it can cause problems
with other technologies.
■■class Used with CSS to specify one or more class names for an element.
■■contenteditable pecifies that the content within the tag can be edited.S
■■contextmenu User can right-click an element to display a menu. At the time of this
writing, no browser supports this attribute.
■■dir Enables you to specify left-to-right or right-to-left text direction for the content
in an element.
■■draggable pecifies whether an element is draggable.S
■■dropzone Enables you to specify the behavior of the dragged data when it’s
dropped. Data can be copied, moved, or linked.
■■hidden pecifies that an element is not relevant.S
■■id pecifies a unique id for an element.S
■■lang pecifies the language (English, French, German, and so on) of the element’s S
content.
■■spellcheck Used with the lang attribute to enable you to indicate whether the ele-
ment is to have its spelling and grammar checked.
■■style pecifies an inline CSS style for the element.S
■■tabindex Sets the tabbing order of the element.
■■title Provides extra information about the element.
You’ll see many examples of these global attributes in this book.

Working with self-closing tags
You can represent any element that contains no content as a self-closing tag. A self-closing
tag is a beginning tag and an ending tag in one. You end the starting tag with a space, slash,
and greater-than symbol. For example, the <br> element cannot have any content, so here is
the beginning and ending tag in one: <br />.
In XML, any empty element can be written with a self-closing tag, but in HTML5, this can
cause problems in different browsers. The rule of thumb is to use self-closing tags for tags
that cannot have content, such as the <br /> tag. Empty elements that are capable of hav-
ing content but currently don’t have content should have separate end tags. An example is
<div></div>; there is no content, but the beginning and ending tags still exist.

Key
Te rms

Free download pdf