×

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not.

Note: An invisible component also grabs the space over the page. If we use display property, we can create hidden component, which does not grab any space.
Syntax:

visibility: visible| hidden| collapse| initial| inherit;

Visibility Attributes

AttributesDescription
visibleThis attribute is used as a default value. The visible attribute describes that a component is visible.
hiddenIt describes that the component is invisible (still grab the space).
collapseThis value is only applied to various tables. It can also be applied to remove the row and the column, but it will not disturb the layout of a table. The space grabbed by the column and row will be applicable for various other contents. When collapse value is applied to any other content, it delivers as “hidden.”
initialThis value is employed to set-up the visibility attribute to its default value.
inheritThis value can acquire this attribute from the parent element.

Visibility Example

<!DOCTYPE html>
<html>
<head>
<style>
h1#visible
{
 visibility: visible;
}
h1#hidden
{
 visibility: hidden;
}
</style>
</head>
<body>
<h1 id= "visible"> This is visible </h1>
<h1 id= "hidden"> This is invisible </h1>
<p>
<strong>
Note:
</strong>
An invisible component also grabs the space over the page.
If we use display property, we can make invisible component that do not grab any space.
</p>
</body>
</html>

Output:

CSS Visibility

JavaScript Syntax:

object.style.visibility=  “hidden”;

Example:

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV
{
 margin: left;
 width: 400px;
 height: 200px;
 background-color: lightblue;
 border: 1px solid black;
}
</style>
</head>
<body>
<p> Click on the "Click Here" button to set the visibility attribute and hide the div component.
</p>
<button onclick= "myFunction()">Click Here</button>
<div id="myDIV">It is my DIV component.</div> 
<p><strong>Note:</strong>
An invisible component also grabs the space over the page. </p> 
<script> 
function myFunction() { 
    document.getElementById("myDIV").style.visibility = "hidden"; 
} 
</script>
</body>
</html>

Output:

CSS Visibility

Related Topics

CSS Background Color

It is one of the CSS properties to apply styling to html elements.This property is used to apply the background color to any HTML element.The background of an element includes...

2 minutes read.

How to change background color in CSS

How to change background color in CSS? The background-color property in CSS would be used to specify the color of an element's background. As the element's background, it uses solid colors. The...

3 minutes read.

CSS Radio Button

Radio Button A radio button has been defined as an element of HTML. It can support us to take any input from the user. But it is challenging to design a...

4 minutes read.

CSS Box-shadow

CSS Box-shadow This property is referred to include effects as shadow-like around an element’s frame. Syntax box-shadow: h-offset v-offset blur spread color |inset|inherit|none; Property values Following are the various property values which can be used...

3 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

CSS Text-stroke

Text-stroke Text-stroke CSS property inserts the stroke to any text and gives a decoration option to them also. It describes the stroke’s width and color for various text characters. It is...

2 minutes read.

How to change the font in CSS

How to change the font in CSS? Professionals can't deny typefaces — how users organize and style text — if we want to completely customize the website's design. One may wish...

4 minutes read.

Difference between HTML and CSS

HTML HTML stands for HyperText Markup Language and is used to create web pages and websites and web applications, which means we can create static web pages. Html is a scripting...

3 minutes read.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The...

4 minutes read.

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

How to use google fonts in CSS

Fonts: - Fonts are used to make our website look more beautiful. Choosing appropriate font according to the web design or layout is also important. Many typefaces are accessible in...

4 minutes read.

CSS Gradient

CSS Gradient: The CSS gradient property is applied to show the smooth transition inside two specified colors or more than two specified colors. Need of CSS Gradient The following are a few...

4 minutes read.

CSS Overflow

CSS Overflow: The Overflow property in CSS is used to manage the content if it overflows from its container of the block level. We have seen that all the elements...

3 minutes read.

How to resize an image in CSS

How to resize an image in CSS? The resize image attribute is used in responsive web design to resize images to fit within the div container automatically. The resize image attribute...

3 minutes read.

CSS Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

How to get rid/remove of bullet pioints in CSS

We include a list of items on the web pages that were sometimes numbered and sometimes bulleted in various styles. In HTML, there are two kinds of lists: ordered and unordered...

3 minutes read.