Professional Documents
Culture Documents
& Paragraph
O
B CHAPTER Objectives
J • to examines block elements in detail.
E
• to know the three different list types in HTML: numbered,
C bulleted, and definition. Learned how to define and format each
type of list and how you can nest lists for more flexibility.
T
I • to know various image formats supported “natively” by most user
agents and how to incorporate them into Web documents.
V
E
S
HTML Headings
H
E Headings are important in HTML documents.
I Since users may skim your pages by its headings, it is important to use
headings to show the document structure.
N
H1 headings should be used as main headings, followed by H2 headings,
G then the less important H3 headings, and so on.
S
HTML Lines
L
I HTML Lines
N The <hr /> tag creates a horizontal line in an HTML page.
E The hr element can be used to separate content:
S
HTML Comments
C
O HTML Comments
M
Comments can be inserted into the HTML code to make it more
M readable and understandable. Comments are ignored by the browser and are
not displayed.
E
Comments are written like this:
N
T <!-- This is a comment -->
S
TRY it in
YOURSELF
HTML Headings
Headings
How to display headings in an HTML document.
T <html>
<body>
R
Y <h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
I <h5>This is heading 5</h5>
<h6>This is heading 6</h6>
T
</body>
</html>
HTML Comments
Hidden comments
T How to insert comments in the HTML source code.
R
<html>
Y <body>
T </body>
</html>
HTML Lines
Horizontal lines
T How to insert a horizontal line.
R <html>
<body>
Y <p>The hr tag defines a horizontal rule:</p>
<hr />
<p>This is a paragraph</p>
<hr />
I <p>This is a paragraph</p>
<hr />
T <p>This is a paragraph</p>
</body>
</html>
L HTML <br> Tag
I
N Definition and Usage
The <br> tag inserts a single line break.
E The <br> tag is an empty tag which means that it has no end tag.
Browser Support
B The <br> tag is supported in all major browsers.
R Differences Between HTML and XHTML
E In HTML the <br> tag has no end tag.
In XHTML the <br> tag must be properly closed, like this: <br />.
A
K
S
L HTML <br> Tag
I Standard Attributes
B
R
E
A Event Attributes
K The <br> tag does not support any event attributes.
S
HTML Paragraph
P
A
Paragraphs
R
In HTML, paragraphs are delimited by the paragraph tag, <p>. The
A paragraph tag controls the line spacing of the lines within the paragraph as well as
G the line spacing between paragraphs. The default spacing is single space within the
paragraph, and double-space between paragraphs.
R
Each paragraph in your document should start with an opening
A paragraph tag (<p>) and end with a closing paragraph tag (</p>)
P
H
HTML Paragraph
P
A
<p> tag (paragraph tag)
R
A This tag indicates the beginning of a new paragraph. </p> is
optional.
G We can align the paragraph in 4 ways by the following
<p align=“left”>------</p>
R <p align=“right”>------</p>
A <p align=“center”>------</p>
<p align=“justify”>------</p>
P
H
Q HTML Quoted Text
U
O • The <blockquote> tag is used to delimit blocks of quoted text. For
T example, the following code identifies the beginning paragraph of
the Declaration of Independence as a quote:
E
D
T
E
X
T
TRY it in
YOURSELF
HTML <br> tag
A line break is marked up as follows:
T <html>
<body>
R
Y <p>
To break<br />lines<br />in a<br
/>paragraph,<br />use the br element.
</p>
I
</body>
T </html>
HTML Paragraph
A paragraph is marked up as follows:
<html>
<body>
T <p>
This paragraph
contains a lot of lines
R in the source code,
but the browser
Y ignores it.
</p>
<p>
This paragraph
contains a lot of spaces
I in the source code,
but the browser
T ignores it.
</p>
<p>
The number of lines in a paragraph depends on the size of your browser window. If you resize the browser window,
the number of lines in this paragraph will change.
</p>
Soft Hyphens
Occasionally, you will want to allow a browser to hyphenate long words to
H better
justify a paragraph. For example, consider the following code
Y <p style=“text-align: justify;”>The morbid fear of the number 13, or
triskaidekaphobia, has plagued some important historic figures like Mark
P Twain
H and Napoleon.</p>
N To do so, you can use the text-indent property of the paragraph tag
and an applicable style. For example, if you wanted the first line of all
D paragraphs to be indented by half an inch, you would use a style
E similar to the following:
N <style type=“text/css”>
p { text-indent: .5in; }
T </style
S
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>First Line Indents</title>
<style type=“text/css”>
I p{ text-indent: 0.5in; }
</style>
N </head>
<body>
D <p>When in the Course of human events, it becomes necessary for one people to dissolve the
political bands which have connected them with another, and to assume among the powers
E of the earth, the separate and equal station to which the Laws of Nature and of Nature’s God entitle
them, a decent respect to the opinions of mankind requires that they should
declare the causes which impel them to the separation.</p>
N
<p>We hold these truths to be self-evident, that all men are created equal, that they are endowed by
T their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of
Happiness.--That to secure these rights, Governments are instituted among Men, deriving their
S just powers from the consent of the governed, --That whenever any Form of Government becomes
destructive of these ends, it is the Right of the People to alter or to abolish it, and to
institute new Government, laying its foundation on such principles and organizing its powers in such
form, as to them shall seem most likely to effect their Safety and Happiness.
Prudence, indeed...</p>
</body>
</html>
D
I DIV Elements
V
The <div> tag is used to
delimit divisions of a document, which can include several
E paragraphs or other
L block elements.
Example: <ol> <li> Rama. <li> Raghu. <li> Sita. </ol> Output:- 1.Rama.
2.Raghu. 3.Sita.
HTML Ordered Lists
You can nest lists of the same or different types. For example, suppose you
L have abulleted list and need a numbered list beneath one of the items, as
shown:
I
S ✦ Send us a letter detailing the problem. Be sure to include the following:
1. Your name
T 2. Your order number
3. Your contact information
S 4. A detailed description of the problem
HTML Nested List
In such a case, you would nest an ordered list inside an unordered one, as shown in
the following code:
I What can you do to ensure your pages download quickly? There are a few things:
✦ Limit image file sizes.
M ✦ Limit the number of images.
✦ Reuse images as much as possible so images can be loaded from cache.
A ✦ Use frames so only part of the browser windows need to reload.
✦ Use text rather than images, where possible.
G Image file sizes
E You can limit image file sizes by doing the following:
S ✦ Using the maximum compression your image will take
✦ Using the smallest bit-depth your image can stand
✦ Minimizing the dimensions of your image on the page
Test your pages at 640 × 480, 800 × 600, and 1024 × 768 to see how they will look to
different visitors. Often, an image that renders well at 1024 × 768 and doesn’t
dominate the page will look huge and overbearing at 640 × 480.
Number of images
G Note The <img> tag has no closing tag. However, in XHTML the <img> tag must
be closed:
E <img alt=“A picture of a cat” src=“cat.jpg” />
S The src attribute’s value can be a file on the same Web server as the document, or
any valid URL pointing to an image on a different Web server. Just as with the anchor
tag, you can use absolute or relative URLs to specify the location of the image to
display. The reasons for using either URL are the same as the reasons for using
absolute or relative URLs in anchor tags
Image Alignment
If the user agent cannot fit the image on the current line, it will wrap it to the
I next line and follow the paragraph’s alignment and formatting.
Note how the default formatting (at least for Internet Explorer) of the image is
M to be aligned with the baseline of neighboring text. This isn’t always ideal. At
times, you will want to specify the alignment of the image as it relates to the
A text and other objects around it. Image alignment can be controlled by using
the align attribute with the <img> tag.
G
Align Attribute Values Value Function
E Top Align with the top of nearby text or object
Bottom Align with the bottom of nearby text or object
S Middle Align with the middle of nearby text or object
Left Align to the left of nearby text or object
Right Align to the right of nearby text or object
Image Alignment
However, the align attribute has been deprecated in favor of using
I styles for image alignment. The following CSS properties can be used to help
align images:
M
✦ text-align—Used in surrounding text, this property aligns the text around an
A image (versus aligning the image itself). See Chapter 8 for more information
on using the text-align property.
G
✦ float—Floats the image to the right or left of the user agent. Note that some
E user agents do not support the float property. The float property allows text
and other objects to wrap next to the image.
S
✦ vertical-align—Aligns the image vertically with neighboring text or objects.
Image Alignment
<p><img alt=“Picture of a cat” src=“cat.jpg” style=“float: right” width=“70px”>
I How does GIF work? Simply put, GIF indexes images to an 8-bit palette. The
system palette is 256 colors. Before you can save your file in GIF format, the
M utility you are using simply makes its best guess at mapping all your colors to
one of the 256 colors in an 8-bit palette. p>
A
G
E
S
I
Size and Scaling
M
You can specify the size of an image by using the height and width
A attributes of the <img> tag. These attributes accept pixel and percentage
values, allowing you to specify the exact size of an image or a size relative to
G the current size of the browser window.
E Get in the habit of always using the width and height attributes with your
<img> tags. These attributes allow the user agent to reserve the correct
S amount of space for the image while it continues to render the rest of the
document. Without these attributes, the user agent must wait for the image to
be loaded before continuing to load the rest of the document.
Image Borders
You can use CSS styles to create borders around images. Previous versions of HTML
supported a border attribute for the <img> tag, which worked similarly to the
I border attribute of the <table> tag. However, this attribute has been deprecated
for use with the <img> tag. Instead, you should use styles.
M
For example, to define a 4-pixel-wide border around an entire image, you can use the
A following code:
I Tip
M To simplify defining a different border on one side of an image, use the border
property first to define a border on all sides and then the appropriate borderside
A property for the side that is the exception, overriding the previous setting
for that side. For example, to create a border on all sides of an image except the
G right, you could specify border-top, border-bottom, border-left, and
border-right properties individually. Or, you could use just border and
E border-right:
I
M
A
G
E
S
HTML Images