Want to share your CSS expertise with others? Apply to the MDN Fellowship by April 1! http://mzl.la/MDNFellowship

mozilla

Revision 16527 of display

  • Revision slug: CSS/display
  • Revision title: display
  • Revision id: 16527
  • Created:
  • Creator: DBaron
  • Is current revision? No
  • Comment /* Specifications */ nothing stable+useful on display from css3 yet

Revision Content

{{template.CSSRef()}}

Summary

This property specifies the type of rendering box used for an element. In a language such as HTML where existing elements have well-defined behavior, default 'display' property values are taken from behaviors described in the HTML specifications or from the browser/user default stylesheet. In languages where display behavior is not defined (like XML), the default value is 'inline'.

In addition to the many different allowed display box types, one other value, "none", allows the display of an element to be turned off; all child elements also have their display turned off. The document is rendered as though the element did not exist in the document tree. This value allows for powerful capabilities, but should be used with caution.

  • Initial value: inline
  • Applies to: all elements
  • Inherited: no
  • Percentages: N/A
  • Media: Visual
  • Computed value: as specified, except for root element, floated elements, and absolutely positioned elements (see ???)

Syntax

display: <display-value> | {{template.Cssxref("inherit")}}

Values

<display-value> 
The Display Value can be any of the following values.
  • inherit : Explicitly sets the value of this property to that of the parent.
  • none : This value turns off the display of an element (it has no effect on layout); all child elements also have their display turned off unconditionally. The document is rendered as though the element did not exist in the document tree. To render an element box's dimensions in the document formatting scheme, yet have its contents be invisible, see the 'visibility' property.
  • inline : This causes the element to generate one or more inline element boxes.
  • block : This causes the element to generate a block element box.
  • inline-block : Introduced in CSS 2.1. This causes the element to generate a block element box that will be flowed with surrounding content as if it were an single inline box (behaving much like a replaced element would.)
  • list-item : This causes the element to generate a block box for the content and a separate list-item inline box.
  • marker : This causes an additional marker box to be generated along with the content box. Generated content using the :before and :after pseudo-elements with this display value will place content in the marker box. If a marker is used with another type of element, the value is treated as "in-line." The position of the marker will lie outside the block box.
  • compact : Depending on context, this value for the display property creates either an in-line or block level rendering box. In each case different CSS properties may apply to the compact element. In a block level context, the compact element is rendered in the left or right margin of the block element. The compact element participates in line-height calculations for the current line, and the 'vertical-align' property value is relative to the block element.
  • run-in : Depending on context, this value for the display property creates either an in-line or block level rendering box. In each case different CSS properties may apply to the run-in element. Properties for the run-in element are inherited from its parent element in the document tree, not from the block element box it participates in.
  • table-header-group|table-footer-group : These values cause the element to behave like the corresponding THEAD and TFOOT HTML table elements which these values take their name from.
  • table : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
  • inline-table : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
  • table-caption : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
  • table-cell : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
  • table-row|table-row-group : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
  • table-column|table-column-group : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.

Examples

{{template.CSSRefExampleLink("display")}}

Ext/Doc: p  { display: block }
In-Line:  <p STYLE="display: block">text</p>

Notes

  • CSS1 Conformance: browsers may legally ignore the 'display' property and instead use browser defaults for each element.
  • In CSS1 the default value for this property was "block." In CSS2 it has been changed to "inline".
"Block" Versus "In-line" Elements
  • Block-level elements create vertically distinct blocks of content (in the visual context) - generally using a line-break before and after the content. Only this value for the 'display' is allowed to generate a positioned element. Block behavior is exhibited by such HTML elements as BLOCKQUOTEs, DIVs and Headings. 'Display' property values creating a block element type: 'block', 'list-item', 'table, 'compact' and 'run-in'
  • In-line elements do not create distinct blocks of content; element content is rendered using a line box (content is distributed line by line within a containing physical or virtual block element.) In-line behavior is exhibited by such HTML elements as physical and virtual character formatting, non-floated images and unmarked content. 'Display' property values creating an in-line element type: 'inline', 'inline-table', 'compact' and 'run-in'.

Specifications

Browser compatibility

Browser Lowest Version
Internet Explorer 4
Netscape 4
Opera 3.5

See also

visibility, position, float

Revision Source

<p> 
{{template.CSSRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p>This property specifies the type of rendering box used for an element. In a language such as HTML where existing elements have well-defined behavior, default 'display' property values are taken from behaviors described in the HTML specifications or from the browser/user default stylesheet. In languages where display behavior is not defined (like XML), the default value is 'inline'.
</p><p>In addition to the many different allowed display box types, one other value, "none", allows the display of an element to be turned off; all child elements also have their display turned off. The document is rendered as though the element did not exist in the document tree. This value allows for powerful capabilities, but should be used with caution. 
</p>
<ul><li> Initial value: inline
</li><li> Applies to: all elements
</li><li> Inherited: no
</li><li> Percentages: N/A
</li><li> Media: <a href="en/CSS/Media/Visual">Visual</a>
</li><li> Computed value: as specified, except for root element, <a href="en/CSS/float">floated</a> elements, and <a href="en/CSS/position">absolutely positioned</a> elements (see ???)
</li></ul>
<h3 name="Syntax"> Syntax </h3>
<p><code>display:</code>  &lt;display-value&gt; | {{template.Cssxref("inherit")}}
</p>
<h3 name="Values"> Values </h3>
<dl><dt> &lt;display-value&gt; </dt><dd> The Display Value can be any of the following values.
</dd></dl>
<ul><li> <b>inherit</b> : Explicitly sets the value of this property to that of the parent.
</li></ul>
<ul><li> <b>none</b> : This value turns off the display of an element (it has no effect on layout); all child elements also have their display turned off unconditionally. The document is rendered as though the element did not exist in the document tree. To render an element box's dimensions in the document formatting scheme, yet have its contents be invisible, see the 'visibility' property.
</li></ul>
<ul><li> <b>inline</b> : This causes the element to generate one or more inline element boxes.
</li></ul>
<ul><li> <b>block</b> : This causes the element to generate a block element box.
</li></ul>
<ul><li> <b>inline-block</b> : Introduced in CSS 2.1. This causes the element to generate a block element box that will be flowed with surrounding content as if it were an single inline box (behaving much like a replaced element would.)
</li></ul>
<ul><li> <b>list-item</b> : This causes the element to generate a block box for the content and a separate list-item inline box.
</li></ul>
<ul><li> <b>marker</b> : This causes an additional marker box to be generated along with the content box. Generated content using the :before and :after pseudo-elements with this display value will place content in the marker box. If a marker is used with another type of element, the value is treated as "in-line." The position of the marker will lie outside the block box.
</li></ul>
<ul><li> <b>compact</b> : Depending on context, this value for the display property creates either an in-line or block level rendering box. In each case different CSS properties may apply to the compact element. In a block level context, the compact element is rendered in the left or right margin of the block element. The compact element participates in line-height calculations for the current line, and the 'vertical-align' property value is relative to the block element.
</li></ul>
<ul><li> <b>run-in</b> : Depending on context, this value for the display property creates either an in-line or block level rendering box. In each case different CSS properties may apply to the run-in element. Properties for the run-in element are inherited from its parent element in the document tree, not from the block element box it participates in.
</li></ul>
<ul><li> <b>table-header-group|table-footer-group</b> : These values cause the element to behave like the corresponding THEAD and TFOOT HTML table elements which these values take their name from.
</li></ul>
<ul><li> <b>table</b> : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
</li></ul>
<ul><li> <b>inline-table</b> : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
</li></ul>
<ul><li> <b>table-caption</b> : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
</li></ul>
<ul><li> <b>table-cell</b> : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
</li></ul>
<ul><li> <b>table-row|table-row-group</b> : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
</li></ul>
<ul><li> <b>table-column|table-column-group</b> : These values cause the element to behave like the corresponding HTML table element which these values take their name from. The 'inline-table' value does not have a direct mapping in HTML.
</li></ul>
<h3 name="Examples"> Examples </h3>
<p>{{template.CSSRefExampleLink("display")}}
</p>
<pre>Ext/Doc: p  { display: block }
In-Line:  &lt;p STYLE="display: block"&gt;text&lt;/p&gt;
</pre>
<h3 name="Notes"> Notes </h3>
<ul><li> CSS1 Conformance: browsers may legally ignore the 'display' property and instead use browser defaults for each element.
</li><li> In CSS1 the default value for this property was "block." In CSS2 it has been changed to "inline". 
</li></ul>
<h5 name=".22Block.22_Versus_.22In-line.22_Elements"> "Block" Versus "In-line" Elements </h5>
<ul><li> <b>Block-level elements</b> create vertically distinct blocks of content (in the visual context) - generally using a line-break before and after the content. Only this value for the 'display' is allowed to generate a positioned element. Block behavior is exhibited by such HTML elements as BLOCKQUOTEs, DIVs and Headings. 'Display' property values creating a block element type: 'block', 'list-item', 'table, 'compact' and 'run-in'
</li></ul>
<ul><li> <b>In-line elements</b> do not create distinct blocks of content; element content is rendered using a line box (content is distributed line by line within a containing physical or virtual block element.) In-line behavior is exhibited by such HTML elements as physical and virtual character formatting, non-floated images and unmarked content. 'Display' property values creating an in-line element type: 'inline', 'inline-table', 'compact' and 'run-in'.
</li></ul>
<h3 name="Specifications"> Specifications </h3>
<ul><li> <a class="external" href="http://www.w3.org/TR/CSS1#display">CSS 1</a>
</li><li> <a class="external" href="http://www.w3.org/TR/CSS21/visuren.html#display-prop">CSS 2.1</a>
</li></ul>
<h3 name="Browser_compatibility"> Browser compatibility </h3>
<table class="standard-table">
  <tbody><tr>
    <th>Browser</th>
    <th>Lowest Version</th>
  </tr>
  <tr>
    <td>Internet Explorer</td>
    <td>4</td>
  </tr>
  <tr>
    <td>Netscape</td>
    <td>4</td>
  </tr>
  <tr>
    <td>Opera</td>
    <td>3.5</td>
  </tr>
</tbody></table>
<h3 name="See_also"> See also </h3>
<p><a href="en/CSS/visibility">visibility</a>, <a href="en/CSS/position">position</a>, <a href="en/CSS/float">float</a>
</p>
Revert to this revision