Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

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

■■<param> efines a parameter for an objectD
■■<source> efines a multimedia resource for a <D video> or <audio> element
■■<wbr> Optionally breaks up a large word at this element
In earlier versions of HTML, you just used the <br> tag with no ending tag to indicate that
you wanted to start a new line on the webpage. With XHTML, this was a problem because all
beginning tags are required to have matching end tags. HTML5 allows you to use a beginning
tag with no end tag, but a better solution is to use self-closing tags.

Adding expando attributes
Expando attributes are attributes that you define. Expando attributes are also known as
author-defined attributes or simply as custom attributes. Any time you want to attach data
to an HTML tag, you can just create an attribute with the name of your choice and assign
the data. However, the name you create might conflict with either an existing W3C-defined
attribute name or a future W3C-defined attribute name. To ensure that you have no existing
or future naming conflict, assign a name that is prefixed with “data-“.

Quick check
■■You have a webpage with a <span> element that contains the customer’s name.
Along with the name, you want to include the customer number on the <span>
element, but you don’t want to display the customer number. How can you
write the <span> element for a customer called Contoso Ltd with customer
number 123?

Quick check answer
■■Use an expando attribute to hold the customer number as follows.
<span data-customerNumber='123'>Contoso Ltd</span>

Adding comments
You can add comments to your HTML source by using the following syntax.
<!--comment here -->

Comments are not displayed on the rendered browser page but are sent to the browser.
Comments can help document your source.
No spaces are allowed between the <! characters and the -- characters at the beginning
of the comment, but spaces are allowed between the -- characters and the > character at the
end of the comment tag. This seemingly weird behavior means that you cannot have back-
to-back dashes (--) in your comment because this combination causes HTML syntax errors.
In addition, you cannot end a comment with three dashes, such as <!-- and then it hap-
pened---> because this also generates a syntax error.

Key
Te rms

Free download pdf