In CSS, the display property specifies how an element is displayed, while the visibility property specifies if an element should be visible or hidden. The display property is very useful in CSS. However, it is also one of the least well-known, especially by those just learning CSS.
The visibility property can be used to show or hide elements. You should note that if you set the visibility property to invisible, the element still occupies the space on the page. If you want to make an element invisible and not take up space on the page, use the display property and set the value to
The visibility property can be assigned the following values:
collapse (for tables only), and
inherit. Some browsers do not support
inherit. You should only use this property if you are trying to hide an element and still allow it to occupy the space on the page.
The display property is very flexible and is a great tool in the CSS toolbox. There are many values that can be assigned to this property. However, the most common values are
block. This is because we can use these two values to change some of the element’s default display behavior.
For example, some HTML elements are of type:
block such as headings, paragraphs, and divs. Other HTML elements such as
inline. We can easily change the behavior of an
inline element to act as a
block element by using this property.
You should note that changing the display type of an element changes only how the element is displayed, not what kind of element it is. For example, an
inline element set to
display:block is not allowed to have block elements nested within it.
Here is a listing of the possible values you can specify for the display property. Not all of the values are supported by all of the browsers.
|The element will not be displayed.
|The element is displayed as a block element.
|The element is displayed as an inline element.
|Placed as an inline element with other adjacent elements but behaves like a block element.
|Element is displayed as an inline table.
|Inherits the display property of the parent element.
|Displayed as a list item.
|Becomes inline or block element depending on child elements.
|Element is displayed as a table.
|Element is displayed as a table caption.
|Element is displayed as a table cell.
|Element is displayed as a table column.
|Element is displayed as a table column group.
|Element is displayed as a table footer group.
|Element is displayed as a table header row.
|Element is displayed as a table row.
|Element is displayed as a table row group.
inherit are not supported in Internet Explorer 7 and earlier. Internet Explorer 8 requires a
!DOCTYPE specified in the HTML document. Internet Explorer 9 does support the values.