38 CHAPTER 2 Getting started with HTML5
NOTE USE THE <SCRIPT> ELEMENT CAREFULLY
When using the <script> element to reference an external JavaScript file, the element will
not have content when used in this context, but you must always include a separate end
tag as follows.
<script src="/Scripts/MyCode.js"></script>
A symptom of incorrect usage of the <script> element is when the browser renders a blank
screen, but you can view the source, and all its content is there.
Quick Check
■■You want to use the <script> element to include a JavaScript file named MyCode.
js in the scripts folder. What is the proper syntax?
Quick Check Answer:
■■<script src="/Scripts/MyCode.js"></script>
Working with void elements
Most but not all elements can have content, and the content can include elements with
content. Elements are not required to have content, but some elements cannot have content.
These are called void elements. For example, the <br> tag represents a line break and cannot
have any content.
The following is a list of void elements in HTML5.
■■<area> Defines a hyperlink area with some text in an image map
■■<base> Specifies the document’s base URL or target for all relative URLs in the
document
■■<br> Represents a line break
■■<col> efines the properties of one or more columns within a <D colgroup> element
■■<command> efines a command that can be invoked by a userD
■■<hr> pecifies a thematic change in contentS
■■<img> efines an imageD
■■<input> efines a typed data field that allows the user to edit the dataD
■■<link> efines a relationship between a document and an external resource such as D
a cascading style sheet
■■<keygen> efines a key-pair generator control for forms that is used to encrypt data D
that will be passed to the server
■■<meta> efines metadata that describes the HTML documentD
Key
Te rms