Home

How to Control Text Blocks in HTML5

|
|  Updated:  
2016-03-26 14:02:55
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

Blocks of text build the foundation of your web page. You use blocks of text to create such things as headings, paragraphs, and lists. You can break those blocks into smaller pieces to better guide readers through your content.

Block quotes

A block quote is a quotation, or an excerpt from a copyrighted source, that you set apart on a page. Use the

element to enclose quotations:


  
    Famous Quotations

An Inspiring Quote

When I need a little inspiration to remind me of why I spend my days in the classroom, I just remember what Lee Iococca said:

In a completely rational society, the best of us would be teachers and the rest of us would have to settle for something else.

Most web browsers display block quote content with a slight left indent, as shown in in this figure.

image0.jpg

Preformatted text

Ordinarily, HTML ignores white space inside documents. That’s why a browser won’t display any of a block element’s

  • Hard returns.

  • Line breaks.

  • Large white spaces.

The following markup includes various hard returns, line breaks, and lots of spaces. The figure shows that the web browser ignores all of this.

image1.jpg

This is a paragraph with a lot of white space thrown in for fun (and as a test of course).

The preformatted text element (

) instructs browsers to keep all white space intact while it displays your content. (As shown in the code sample.) Use the 
element in place of the

element to make the browser apply all your white space, as shown in the figure.

image2.jpg

  
    White Space
This is a paragraph
                           with a lot of white space
                                  thrown in for fun (and as a test of course).
    

You may want the browser to display white spaces in an HTML page where proper spacing is important, such as for

  • Code samples

  • Columnar data, numbers, or other format-sensitive text

  • Text tables

You could nest

 elements inside 
elements to carefully control how lines of quoted text appear on the page. Or better yet, forget about these tags and use CSS to position text blocks inside
elements.

Horizontal rules

Using a horizontal rule element (hr) lets you include solid straight lines called rules on your page.

The browser creates the rule based on the hr element, so users don’t wait for a graphic to download. A horizontal rule is a good option to

  • Break a page into logical sections.

  • Separate headers and footers from the rest of the page.

Formatting

When you include an


element on your page, as in the following HTML, the browser replaces it with a line, as shown in the figure.

image3.jpg

  
    Horizontal Rules

This is a paragraph followed by a horizontal rule.


This is a paragraph preceded by a horizontal rule.

A horizontal rule always sits on a line by itself; you can’t add the


element in the middle of a paragraph (or other block element) and expect the rule to appear in the middle of the block.

The following bit of HTML creates a horizontal rule that takes up 45 percent of the page width, is 4 pixels (px) high, is aligned to the center, and has shading turned off:

    

This is a paragraph followed by a horizontal rule.


This is a paragraph preceded by a horizontal rule.

The figure shows how adding attributes in the preceding example alters how a rule appears. (Note: These attributes are deprecated, and best replaced with CSS equivalents. Deprecated attributes are covered online, and the preceding HTML is not valid.)

image4.jpg

About This Article

This article is from the book: 

About the book author:

Ed Tittel is a 28-year veteran of the computer industry. A seasoned author and consultant, Ed has more than 140 books to his credit.

Chris Minnick is an accomplished author, teacher, and programmer. Minnick authored or co-authored over 20 books, including titles in the For Dummies series. He has developed video courses for top online training platforms and he teaches programming and machine learning to professional developers at some of the largest global companies.