One reason for nesting is to apply basic styles to text-based elements.
Earlier, you saw the code for a paragraph element. We can now make the text bold by surrounding
the element content with a strong element:
Here is a paragraph.
HTML doesn??™t have a hard-and-fast rule regarding the case of tags, unlike XHTML,
which we??™ll shortly be talking about and which will be used throughout the book. If
you look at the source code of HTML pages on the Web, you may see lowercase tags,
uppercase tags or, in the case of pages put together over a period of time, a mixture
of the two. That said, it??™s still good practice with any markup language to be consistent,
regardless of whether the rules are more flexible.
The W3C website is found at www.w3.org. The site offers numerous useful tools,
including validation services against which you can check your web pages.
AN INTRODUCTION TO WEB DESIGN
7
1
Note that the strong tags are nested within the paragraph tags (
), not the other
way around. That??™s because the paragraph is the parent element to which formatting is
being applied. The paragraph could be made bold and italic by adding another element,
emphasis (
), as follows:
Here is a paragraph.
In this case, the strong and em tags could be in the opposite order, as they??™re at the same
level in the hierarchy. However, you must always close nested tags in the reverse order to
that in which they??™re opened, as shown in the previous code block, otherwise some
browsers may not display your work as intended.
Pages:
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61