Open In App

HTML DOM Style display Property

The HTML DOM Style display property is used to set or return the display type of an element. It is similar to the visibility property, which displays or hides the element. With a slight difference in display: none, hiding the entire element, while visibility: hidden meaning only the contents of the element will be invisible, but the element will remain in its original position and size. 

Syntax

object.style.display
object.style.display = value;

Property Values

Property Value

Description

inlineIt is the default value. It renders the element as an inline element.
blockIt renders the element as a block-level element.
compactIt renders the element as a block-level or inline, depending on the context.
flexIt renders the element as a block-level flex box.
inline-blockIt renders the element as a block box inside an inline box.
inline-flexIt renders the element as an inline-level flex box.
inline-tableIt renders the element as an inline table.
list-itemIt renders the element as a list.
markerIt sets content before or after the box as a marker.
noneIt will not display any element.
run-inIt renders the element as block-level or inline, depending on the context.
tableIt renders the element as a block table, with a line break before and after the table.
table-captionIt renders the element as a table caption.
table-cellIt renders the element as a table cell.
table-columnIt renders the element as a column of cells.
table-column-groupIt renders the element as a group of one or more columns.
table-footer-groupIt renders the element as a table footer row.
table-header-groupIt renders the element as a table header row.
table-rowIt renders the element as a table row.
table-row-groupElement is rendered as a group of one or more rows.
initialIt sets the display property to its default value.
inheritIt inherits the display property values from its parent element.

Return Value

It returns a string, representing the display type of the element. 

Example 1: This example describes the inline property value. 

<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM Style display Property
    </title>
</head>

<body>
    <h2>
        HTML DOM Style display Property
    </h2>

    <p>
        Click on the button to set
        display property
    </p>

    <div id="GFG">GeeksforGeeks</div>

    <button onclick="myFunction()">
        Click Here!
    </button>

    <!-- script to set display property -->
    <script>
        function myFunction() {
            document.getElementById("GFG").style.display = "inline";
        }
    </script>
</body>

</html>

Output:

HTML-DOM-Style-display-Property


Example 2: This example describes the none property value. 

<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM Style display Property
    </title>
</head>

<body>
    <h2>
        HTML DOM Style display Property
    </h2>

    <p>
        Click on the button to set
        display property
    </p>

    <div id="GFG">GeeksforGeeks</div>

    <button onclick="myFunction()">
        Click Here!
    </button>

    <!-- script to set display property -->
    <script>
        function myFunction() {
            document.getElementById("GFG").style.display = "none";
        }
    </script>
</body>

</html>

Output:

HTML-DOM-Style-display-Property-2

Example 3: This example describes the table-caption property value. 

<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM Style display Property
    </title>
</head>

<body>
    <h2>
        HTML DOM Style display Property
    </h2>

    <p>
        Click on the button to set
        display property
    </p>

    <div id="GFG">Welcome GeeksforGeeks</div>

    <button onclick="myFunction()">
        Click Here!
    </button>

    <!-- script to set display property -->
    <script>
        function myFunction() {
            document.getElementById("GFG").style.display = "table-caption";
        }
    </script>
</body>

</html>

Output:

HTML-DOM-Style-display-Property-3

Example 4: This example describes the block property value. 

<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM Style display Property
    </title>
</head>

<body>
    <h2>
        HTML DOM Style display Property
    </h2>

    <p>
        Click on the button to set
        display property
    </p>

    <div>Welcome <span id="GFG">GeeksforGeeks</span></div>

    <button onclick="myFunction()">
        Click Here!
    </button>

    <!-- script to set display property -->
    <script>
        function myFunction() {
            document.getElementById("GFG").style.display = "block";
        }
    </script>
</body>

</html>

Output:

HTML-DOM-Style-display-Property-4

Supported Browsers

Article Tags :