WE Unit-2 HTML Elements
WE Unit-2 HTML Elements
A block-level element is one that contains a significant block of content that should be displayed on its own line, to break apart long passages of text into manageable portions such as paragraphs, headings, and lists. Many nonempty, block-level elements can contain other block-level elements, and all can contain text and inline elements. As with most word processors, HTML includes several tags to delimit, and hence, format paragraphs of text. These tags include the following: <p>Formatted paragraphs <h1>through <h6>Headings <blockquote>Quoted text <pre>Preformatted text <div>A division of the document <center>Centered text <BR>Line Break, <HR> Horizontal Rule <ul>,<ol>, <dl>Unnumbered, ordered, and denition lists
Each of the block elements results in a line break and noticeable space padding after the closing tag. As such, the block elements only work when used to format paragraph-like chunks of textthey cannot be used as inline tags.
Formatted Paragraph
The paragraph tag p is used, quite simply, to mark up paragraphs of text: Example: <p> This is a paragraph of text</p> <p>and this is another paragraph.</p> The p element is one of the most commonly used building blocks of HTML. When you use the p element to begin a new paragraph in HTML, it automatically creates a line space above and below the content. This element may contain any text content, but it cant include any block-level elements: only inline or phrase elements can be included. The P element has an attribute called align that will center the content inside the two paragraphs. Example: <HTML> <HEAD><TITLE>Paragraph Example</TITLE> </HEAD> <BODY> <P>This is the first paragraph in the example about the P tag. There really isn't much to say here. </P> <P ALIGN="center"> This is the second paragraph. Again, more of the same. This time the paragraph is aligned in the center. This might not be such a good idea as it makes the text hard to read. </P> <P ALIGN="right"> Here the paragraph is aligned to the right. Rightaligned text is also troublesome to read. The rest of the text of this paragraph is of little importance. </P> <P ALIGN="justify"> Under HTML 4.0-compliant browsers, you are able to justify text. As you may notice, the way browsers tend to justify text is sometimes imprecise. Furthermore, not all browsers support this attribute value. </P> </BODY> </HTML>
Headings
The heading elements are used to create headlines in documents. Six different levels of headings are supported: <H1>, <H2>, <H3>, <H4>, <H5>, and <H6>. These range in importance from <H1>, the most important, to <H6>, the least important. Each heading uses a large, usually bold characterformatting style to identify itself as a heading. HTML automatically adds an extra blank line before and after a heading. <html> <body> <h1> Heading 1 </h1> <h2 ALIGN="center"> Heading 2 </h2> <h3 ALIGN="right"> Heading 3 </h3> <h4> Heading 4 </h4> <h5> Heading 5 </h5> <h6> Heading 6 </h6> <p>Plain body text: The quick brown fox jumped over the lazy dog.</p> </body> </html> An attribute that aligns the text left, right, or center can be added to the heading elements. By default, headings are usually left-aligned, but by setting the ALIGN attribute of the various heading elements, the text may be aligned to the right, left, or center of the screen.
Divisions Tag
The <DIV></DIV> container (DIV stands for division) can be used to enclose and define the alignment for an entire block of page elements. It supports the ALIGN attribute, so you could use it to align a block of text and graphics to CENTER, as in this example:
<DIV ALIGN=CENTER> <H1>This header is centered.</H1> <P >But this text is center-aligned.</P><BR> So are the images above and this line of text.<BR> <P ALIGN=RIGHT>But this text is right-aligned.</P> </DIV>
Note that all the elements between the <DIV> and </DIV> tags are aligned according to the definition given by the <DIV> tag, except for any elements which have their own alignments defined. As is always the case with the ALIGN attribute, it can assume the values LEFT, CENTER, or RIGHT.
Preformatted Text
The <PRE> and </PRE> tags can be used to surround text that shouldnt be formatted by the browser. The text enclosed within the <PRE> tags retains all spacing and returns, and doesnt reflow when the browser is resized. Scroll bars and horizontal scrolling are required if the lines are longer than the width of the window. The browser generally renders the preformatted text in a monospaced font, usually Courier. Some text formatting, such as bold, italics, or links, can be used within the <PRE> tags. The pre element in this example displays as shown in Figure 5-3. The second part of the figure shows the same content marked up as a paragraph (p) element for comparison.
<pre> This is text with a </pre> <p> This is text with a </p>
an
example of lot of curious white space. example of lot of curious white space.
Figure 4-6. The spaces and returns remain intact when the content is rendered.
Line Breaks
The <br> tag is used to add a line break in your HTML page. It causes the browser to stop printing text on that line and drop down to the next line on the page. Because the <br> tag has no end tag (or closing tag), it breaks one of the rules for future HTML (the XML based XHTML), namely that all elements must be closed. Writing it like <br /> is a future proof way of closing (or ending) the tag inside the opening tag, accepted by both HTML and XML.
HTML Lists
There may be times when web designers need to organize information or images in a neat format resembling a list. This allows the designer to group related pieces of items together so they can be clearly seen increasing readability and importance. HTML has tags for this purpose and supports the following three block-level list types: Unordered List Ordered List Definition Lists
Unordered Lists: Unnumbered or unordered lists are usually displayed with bullets, which depict each new line of information to be displayed in the list structure. Unordered lists should be used when needing to display a related group of data without stressing the order in which the data is presented. The following code illustrates an example of an unordered list: <html> <head><title>Unordered List Example</title></head> <body> <ul> <li>List Item 1</li> <li>List Item 2</li> <li>List Item 3</li> <li>List Item 4 </li> </ul> </body> </html>
NOTE: The type="" attribute can be used in the opening <ul> tag to specify a square, circle, or disc shaped bullet. If no bullet is specified, the default solid disk shape is used. Also note that the closing </li> tag is optional when entering <li> items.
Numbered Lists: Numbered lists are coded identical to an unnumbered list except for the opening
and closing tag, which are: <ol> </ol>. Numbered lists should be used when needing to display data when order is important. <html> <body> <ol type="A"> <li>List Item <li>List Item <li>List Item <li>List Item </ol> </body> </html>
1 2 3 4
NOTE: The following is a listing of the possible numbering styles for the type="" attribute: VALUE 1 A a I i MEANING Arabic (1, 2, 3, ...) [default] Alphabetic uppercase Alphabetic lowercase Roman numeral uppercase Roman numeral lowercase
Definition Lists: Definition lists can be used for two purposes. If needing to list terms with
definitions, designers can use alternating definition tags <dt> and definition data tags <dd>. Note that using closing tags when using the <dt> and <dd> tags is optional. Designers can also use a definition list when using a custom bullet image instead of the standard bullet types of numbered and unordered lists. If using a custom bullet, only <dd> opening and closing tags should be used to list the bullet images and items. To begin and end a definition list, use the <dl></dl> start and closing tags. The following examples illustrate the two types of definition lists: <html> <body> <dl> <dt><b><i>Word 1</i></b></dt> <dd>This corresponds to the meaning of word 1.</dd><br><br> <dt><b><i>Word 2</i></b></dt> <dd>This corresponds to the meaning of word 2.</dd><br><br> <dt><b><i>Word 3</i></b></dt> <dd>This corresponds to the meaning of word 3.</dd><br><br> </dl> </body> </html> The above HTML code would produce the following results in a web browser:
10
Short quotations
Use the quotation (q) element to mark up short quotations, such as To be or not to be in the flow of text, as shown in this example. Matthew Carter says, <q>Our alphabet hasn't changed in eons.</q>
Citations
The cite element is used to identify a reference to another document, such as a book, magazine, article title, and so on. Citations are typically rendered in italic text by default. Heres an example: <p>Passages of this article were inspired Typography</cite> by James Felici.</p> by <cite>The Complete Manual of
Defining terms
The <dfn> element allows you to specify that you are introducing a special term. Its use is similar to the words that are in italics in the midst of paragraphs in this book when new key concepts are introduced. <p><dfn>Script typefaces</dfn> are based on handwriting.</p>
11
12