Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original
HTML DOM Style display Property
Style display Property
The Style object
Definition and Usage
The display property sets or returns the display type of an element.
Most elements in HTML are "inline" or "block" elements: an inline element has floating content on both its left and right sides. A block element fills the entire line, and nothing is displayed on its left or right side.
The display property also allows the author to show or hide an element. It is similar to the visibility property. However, if you set display:none, the entire element is hidden; if you set visibility:hidden, the content of the element is invisible but the element keeps its original position and size.
Syntax
Set the display property:
Object.style.display="
value
"
Return the display property:
Object.style.display
Value
Description
block
The element is rendered as a block-level element.
compact
The element is rendered as a block-level or inline element, depending on context.
inherit
The value of the display property is inherited from the parent element.
inline
Default. The element is rendered as an inline element.
inline-block
The element is rendered as a block box inside an inline box.
inline-table
The element is rendered as an inline table (similar to
), with no line breaks before and after the table.
list-item
The element is rendered as a list.
marker
This value sets content before and after the box as a marker (used together with the :before and :after pseudo-elements; otherwise this value is the same as "inline").
none
The element is not displayed.
run-in
The element is rendered as a block-level or inline element, depending on context.
table
The element is rendered as a block-level table (similar to
), with line breaks before and after the table.
table-caption
The element is rendered as a table caption (similar to
).
table-cell
The element is rendered as a table cell (similar to
and
).
table-column
The element is rendered as a column of cells (similar to
).
table-column-group
The element is rendered as a group of one or more columns (similar to
).
table-footer-group
The element is rendered as a table footer row (similar to
).
table-header-group
The element is rendered as a table header row (similar to
).
table-row
The element is rendered as a table row (similar to
).
table-row-group
The element is rendered as a group of one or more rows (similar to
).
Browser support
All major browsers support the display property.
**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".
Tips and Notes
**Tip:** If the element is a block element, its display type can be changed via the float property.
Example
Example
Set the element to be invisible when a button is clicked: