HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 4. HTML TAGS AND ATTRIBUTES 41


4.3 Tag Attributes


We can useattributesto modify or customize tags. Attributes are also
calledparametersorproperties.


Attributes are specified right after the tag. Here is an example.



In this example, there are three attribute/value pairs. The first isx=5. The
second isy=hello. The third isz=whatever.


Normally the order does not make any difference. We could have said the
following, and it would mean the same thing.



Exam Question 62(p.339): In HTML does the order in which attributes
are specified make any difference?
Required Answer:no


4.3.1 Blank Attribute Values


If the attribute’s value is blank, you can specify it or leave it off. Here are
three options.


<... attribute="" ...>(the value is explicitly the empty string)


<... attribute= ...>(the value is assumed to be the empty string)


<... attribute ...>(the value is assumed to be the empty string)


The second option,<... attribute= ...>, is legal but it is dangerous and
shouldnotbe used. The following attribute, if any, could be interpreted to
be its value if you are not careful.


Sometimes a missing attribute has a default value. The submit button, for
example, has a default value that is different than specifyingvalue=''.


4.3.2 Spacing


Although it is perfectly legal to have zero or more spaces before the=, and
zero or more spaces after the=, we strongly recommend that spaces not be
placed around the=(equals) sign. It makes things confusing.

Free download pdf