×

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on the page.

All the elements of HTML contain a display value as the default value. It leans on the element type, which we use. The inline and block values are used for most of the elements.

Default properties of CSS display

  • version: css1
  • inherited: no
  • animation supporting: no
  • default value: inline
  • javascript syntax: object.style.display=”none”

Display Values

Some commonly used display values are as below:

  1. display: none;
  2. display: inline;
  3. display: block;
  4. display: inline-block;
  5. display: run-in;

Display none

The display none value is used to remove the HTML elements from web pages. They will not hold any space. These elements are generally applied with JavaScript language to show and hide the elements without recreating and deleting them.

 <!DOCTYPE html>
   <html>
   <head>
   <style>   p.none {   display: none;   }   </style>
   </head>
   <body>   <h1>This heading will visible.</h1>
   <p class="none">This will not   visible.</p>
   <p>We can see that the hidden heading does not   contain any space.</p>
   </body>
   </html>    
CSS Display

Display inline

The display inline holds only the width as much as required. These types of elements do not begin on the new line. Hence, the flow of text does not break.

Some inline elements can be as follows:

  • <a>
  • <b>
  • <img>
  • <span>

Example:

    <!DOCTYPE html>
   <html>
   <head>
   <style>   p.inline {   display: inline;   }   </style>
   </head>
   <body>
   <h1>This is an example of inline display   value.</h1>
   <p class="inline">Java   Language.</p>
   <p class="inline">CSS   Language.</p>
   <p class="inline">C++   Language.</p>
   <p class="inline">Python   Language.</p>
   </body>
   </html>    
CSS Display

Display block

The display block always begins on the new line. It holds-up the entire available width (stretches out towards left and right as much as these elements can). A display block element is a <div> element.

Some examples of display block elements are as below:

  • <div>
  • <p>
  • <form>
  • <section>
  • <footer>
  • <header>
  • <h1> - <h6>

 Example:

<!DOCTYPE html>
   <html>
   <head>
   <style>   p {   display: block;   }   </style> 
  </head>
   <body>
   <h1>This is an example of block display   value.</h1>
   <p>Java Language.</P>  
 <p>C++ Language.</P> 
  <p>Python Language.</P> 
  <p>C Language.</p>  
 <p>JavaScript Language.</p>
</body>   
</html>    
CSS Display

Display Inline-Block

The inline-block CSS elements are quite similar to the inline elements. The main difference between the both is that we can set the height and width in inline-block element.

Example:

 <!DOCTYPE html>
   <html>
   <head>
   <style>  p {   display: inline-block;   }   </style>
   </head>
   <body>
   <h1>This is an example of   inline-block display value.</h1>
   <p>Java   Language.</p>
   <p>CSS   Language.</p>
   <p>C++   Language.</p>
   <p>Python   Language.</p>   
</body>   
</html>   
CSS Display

Display run-in

The display run-in elements can’t work with Mozilla Firefox. They don’t generate a particular box.

  • If a run-in box includes the block box, it will be similar as block.
  • If a block box pursues a run-in box, it will be the block box’s initial inline box.
  • If inline box pursues a run-in box, it will become the block box.

Example:

 <!DOCTYPE html>
   <html>
   <head>
   <style>   p {   display: run-in;   }   </style>
   </head>
   <body>   
<h1>This is an example of run-in display   value.</h1>
   <p>Java Language.</p>
   <p>CSS Language.</p>
   <p>C++ Language.</p>
   <p>Python Language.</p>
   <p>CSS Style.</p>
   </body>
   </html> 
CSS Display

Other Display Values of CSS

Property-value Description
flex It is applied to show a tag as a container of block-level flex. Flex is a new value in CCS3.
Inline-flex It is applied to show a tag as a container of inline-level flex. Inline-flex is a new value in CCS3.
Inline-table It shows a tag as a table in the inline-table.
list-item It enables a tag to behave as a <li> tag.
table It enables a tag to behave as a <table> tag.
table-caption It enables a tag to behave as a <caption> tag.
table-column-group It enables a tag to behave as a <colgroup> tag.  
table-header-group It enables a tag to behave as a <thead> tag.  
table-footer-group It enables a tag to behave as a <tfoot> tag.  
table-row-group It enables a tag to behave as a <tbody> tag.  
table-cell It enables a tag to behave as a <td> tag.
table-row It enables a tag to behave as a <tr> tag.
table-column It enables a tag to behave as a <col> tag.

Related Topics

How to center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 minutes read.

What is CSS used for

What is CSS used for? CSS stands for Cascading Style Sheet. CSS is a stylesheet language for web pages. It specifies how a document created in a markup language looks and...

4 minutes read.

CSS Page-break-after Attribute

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

5 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.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

Untitled Reusable Block

  ...

1 minute read.

CSS Links

CSS Link is used to create styled link. There are various ways to implement it. Styling Links Link can be styled with CSS properties like color, font-family, background etc. Example: <!DOCTYPE html>   <html>   <head>   <style>   a {       color: red;   }   </style>   </head>   <body>   <p><b><a href="https://www.tutorialandexample.com"    target="_blank">This is a link</a></b></p>   </body>   </html> Try Now There are four...

2 minutes read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

CSS Form

You can create attractive HTML form by using CSS. Style input Fields The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style...

2 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 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 Text Effects

Text Effects in CSS We can use distinct text effects used inside the HTML document. Few attributes can be applied to insert the text effects. We can also style various web documents...

5 minutes read.

CSS Lists

CSS Lists: Several properties are available in CSS that are used to manage the lists. Lists are distributed as ordered and unordered kind of lists. The ordered lists provide the...

7 minutes read.

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

7 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes read.

CSS Pagination

CSS Pagination The pagination in CSS is an advantageous approach for indexing of a website’s distinct pages over the homepage. When our site contains multiple pages, we must insert a few...

13 minutes read.

CSS Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 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 Border

CSS Border: The border property of CSS allows us to define the style, color, width, and radius of the element’s border. It is applied to various elements to set-up the...

4 minutes read.