Jump to main content
Menu

Block-Level Elements, Part 2

Horizontal Rules

  • Coded as <hr />, these tags create a horizontal (left to right) line that by default stretches across the entire width of their parent element.
  • Just like <br />, these tags are self-terminated. They cannot contain other tags or any text content.
  • Horizontal rules will have margin space above and below them, but the amount of vertical space varies by browser. Cross-browser testing is recommended to ensure that the result is acceptable, with CSS being used to adjust the space as necessary.
Attribute Usage and Effect Values Default Deprecated?
align Horizontally aligns the rule within its parent element.

Note: This attribute has no impact if the default width of 100% is being used.

  • left
  • center
  • right
left Deprecated
noshade Disables the default three-dimensional visual shading effect, which may be too small to notice at the default size. noshade="noshade" or just noshade Shading occurs by default Deprecated; the CSS properties such as background or background-color to change color
size Determines the height of the line. A number (in pixels, but px is omitted) Usually a few pixels; varies a bit by browser Deprecated; use CSS height property instead
width Determines the width of the line. Pixel value or percentage value 100% Deprecated; use CSS width property instead

Horizontal Rule Example:

See the Pen Horizontal Rules by Jason Withrow (@jwithrow) on CodePen.

Note: When specifying a numerical attribute value in HTML5 pixels are assumed, so just the number needs to be specified. In some cases percentages are allowed and the % character is necessary.

Blockquotes

  • This structural tag is used for block quotations and is coded as <blockquote></blockquote>
  • Blockquotes have default spacing on all sides (margins on all sides)
Attribute Usage and Effect Values Default Deprecated?
cite Contains the URL of the cited text. Text (usually a web address) There is no default value Not deprecated

Blockquote Example:

See the Pen Blockquote by Jason Withrow (@jwithrow) on CodePen.

Unordered Lists

  • Unordered lists are coded as <ul></ul>
  • These contain one or more list items that do not possess a natural sequencing / ordering.
  • Each list item is inside <li></li>
  • The <ul></ul> tags have margin space above and below them (on the top and bottom of the list); the list items are on separate lines but there is no extra vertical space between them.
  • Note: Be careful when nesting lists that the nested <ul></ul> is entirely within the <li></li> holding it.
Attribute Usage and Effect Values Default Deprecated?
compact Instructs the client device to render the list in a more compact fashion; results vary by browser. Specified at the <ul> level. compact="compact" or just compact No compacting occurs Deprecated
type Determines whether discs, circles, or squares are used for the list items.

If specified in a <ul> affects the entire list; if specified in an <li> will only affect that one item (and will override the <ul> setting).

  • disc (filled circle)
  • circle (open circle)
  • square
  • First-level lists default to disc.
  • Second-level default to circle.
  • Third-level and lower default to square (for most browsers)
Deprecated; use the list-style or list-style-type CSS properties

Unordered List Example:

See the Pen Unordered List by Jason Withrow (@jwithrow) on CodePen.

Ordered Lists

  • Ordered lists are coded as <ol></ol>
  • These are used for a group of one or more list items that have a natural sequencing.
  • Each item in the list is surrounded by <li></li>
  • The <ol></ol> tags have a line of margin space above and below them (on the top and bottom of the list); the list items are on separate lines but there is no extra vertical space between them.
  • Be careful when nesting lists that the nested <ol></ol> is entirely within the <li></li> holding it.
Attribute Usage and Effect Values Default Deprecated?
compact Instructs the client device to render the list in a more compact fashion; results vary by browser.

Specified at the <ol> level.

compact="compact" or just compact No compacting occurs Deprecated
start Specifies the number at which the list will start.

Cannot be specified in an <li> and must be specified in an <ol> (if used).

Number (e.g., 5) 1 Deprecated
type Determines what numbering approach is used for the list items.

If specified in a <ol> affects the entire list; if specified in an <li> will only affect that one item (and will override the <ol> setting).

  • 1 (Arabic numerals)
  • a (lowercase alphabet)
  • A (uppercase alphabet)
  • i (lowercase Roman numerals)
  • I (uppercase Roman numerals)
1 Deprecated; use the list-style or list-style-type CSS properties (they offer more choices than what this attribute accepts)
value Specifies the number to be used for a list item; must be specified in <li> (if used). Number (e.g., 5) There is no default value (the browser is tracking list item count automatically) Deprecated

Ordered List Example:

See the Pen Ordered List by Jason Withrow (@jwithrow) on CodePen.

Definition Lists

  • Definition lists are used for defining terms.
  • For example, these would be appropriate for glossaries.
  • The outermost tags are <dl></dl>
  • Within the definition list are tags for the defined term (coded as <dt></dt>) and description (coded as <dd></dd>).
  • The <dl></dl> render with a line of margin space above and below.
  • The <dt></dt> tags typically have their content left-aligned. These tags cannot contain block-level elements.
  • The <dd></dd> tags typically have their content indented and on the line immmediately below the defined term. These tags can contain block-level elements.
Attribute Usage and Effect Values Default Deprecated?
compact Instructs the client device to render the list in a more compact fashion; results vary by browser.

Specified at the <dl> level.

compact="compact" or just compact No compacting occurs Deprecated

Definition List Example:

See the Pen Definition List by Jason Withrow (@jwithrow) on CodePen.

Addresses

  • Coded as <address></address>, this is used to mark up contact information.
  • There are no specialized attributes for this tag.
  • Browsers typically render the address on a new line and italicize the content.
  • Content following </address> appears on the next line.
  • Note: Be careful not to nest this inside <p>, as a validation error will result and rendering issues will arise. Nesting inside <div> is fine.

Address Example:

See the Pen Address by Jason Withrow (@jwithrow) on CodePen.

Preformatted Text

  • Preformatted text is surrounded by <pre></pre> tags.
  • What makes preformatted text unique is that white space inside the tags is preserved, rather than being collapsed down to a single space maximum between characters (as in regular code rendering).
  • Preformatted text also does not wrap to new lines when the browser window is reduced in size; a horizontal scrollbar appears for the browser window (if necessary).
  • Browsers also render preformatted text in a monospace font (so that all characters are equal width; the browser has a default monospace font that is used).
  • It is best to use preformatted text sparingly, given its downsides.
Attribute Usage and Effect Values Default Deprecated?
width This is supposed to instruct client devices concerning how many characters wide the preformatted block is supposed to be, so that the device can make any adjustments necessary to font size, etc.

There is weak browser support for this attribute, so its use is discouraged.

A number representing the amount of characters wide (e.g., 200) There is no default Deprecated; use the CSS width property instead

Preformatted Text Example:

See the Pen Preformatted Text by Jason Withrow (@jwithrow) on CodePen.

Standard Attributes

  • These attributes can be used in essentially all HTML5 tags valid inside of <body> (including <body> itself).
  • None of these attributes are deprecated.
Attribute Usage and Effect
class Used in CSS and the same class value can be specified as many times within a web page as desired.
dir Indicates text directionality, with values of LTR (left-to-right) or RTL (right-to-left).

If supportive, the client device should reverse the text sequence.

When applied to tables, the sequence of columns in the table should invert / flip in supportive devices.

hidden Removes the element from being shown / rendered.

To get the element to be shown again use JavaScript to remove this attribute.

id Unique value used once per web page.

Used in some accessibility enhancements, CSS, and JavaScript.

lang Language used for content within that tag.

Consult ISO standard 639 for 2-letter values.

style Used to specify CSS directly in that tag (this approach is referred to as inline CSS).
title Provides additional information about the content in that tag.

Modern browsers render as a tooltip when the tag is moused over; usually the tooltip appears after a second. This does not trigger on focus, only hover / mouseover.

This can be used to communicate information to assistive technology, but there are scenarios where a user may be unable to use, or lack access to, a pointer input (e.g., a mouse) and not be using a screen reader and they would not get this information.

Deprecated Block-Level Elements

  • These tags have been deprecated either because of their presentational nature (since HTML5 is supposed to be about structure, not presentation) or because another tag exists that takes their place.
  • These are tags you should never use, but you will see them sometimes in existing code. If asked to update a website using these deprecated tags you should also know how to replace them with modern and standards-based approaches.
Element Usage and Effect Preferred Approach
<center></center> Centers the content inside the tag; will often be found surrounding an entire layout. The CSS text-align property is the ideal approach.
<dir></dir> This was supposed to be used for multicolumn directory lists and is structured the same way.

Should render like an unordered list.

Use <ul></ul> or <ol></ol> instead.
<menu></menu> This was supposed to be used for single column menu lists and is structured the same way.

Should render like an unordered list.

Use <ul></ul> or <ol></ol> instead.