search

HTML Display Block

Sep 04, 2024 pm 04:39 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

HTML Display Block is one of HTML’s most important position properties, responsible for placing block-level elements into the display block. While designing a webpage, arranging elements properly in a specific position is always important. Setting a proper position for the layout is one of the most critical tasks. By default, it took the display property as inline. This will always start with a new line and stretch elements from left to right to occupy full-width space. One can set height and width properties to the block-level elements, and it is possible to include other inline or block elements within it.

Syntax:

  • Each and every element is placed on the webpage at a specific location. The property value helps us to define how it should be displayed on the webpage; it will be as follows:
display :block;
  • The syntax for displaying it with position value is as follows:
position :value;
  • In the above syntax, the position is the placement area where actual elements will place. Into the value, we can use a block for displaying block-level elements. So it will be going to use like :
position :block;
  • That HTML Block contains elements like
    ,

    ,

    , as well as one can use inline elements within the display block.
  • With the help of CSS, one can define display property with some specified values like :
  • display: [<display-outside> , <display-inside>] [<display listitem>, <display>, <display-box>]</display-box></display></display></display-inside></display-outside>

    There are different display values for HTML as follows:

    1. none value

    {
    display:none;
    }

    2. inline value

    {
    display:inline;
    }

    3. block value

    {
    display:block;
    }

    4. inline-block value

    {
    display : inline- block;
    }

    All the above values help us to set and control the layout; most of the time, values for the layout are either inline or block. The display block starts with a new line covering the container’s full width to put elements on the web page in the HTML display block. Block-level elements don’t allow you to use other block elements within them.

    How does Block Display in HTML?

    • This format uses boxes placed one after another in a vertical direction. It will start from the top of the containing block.
    • Those blocks are managed with vertical distance between them using equivalent space, known as margin property in the CSS.
    • In this display block formatting process, every box’s left outer side is attached to the left side of its containing block. The same thing will happen with the right edges of containing blocks.
    • Another way to define a display block in HTML is to put block elements down in the horizontal direction, as in English. It will arrange the layout vertically below one by one.
    • As we are using margins, it helps to create space between two boxes or elements, which will separate elements from each other.
    • Block-level elements will occupy all the space in an inline direction, separating our elements into their containing block.
    • As we know, we can set height and width properties to the layout in it, so it helps to put blocks below each other one by one.

    Examples of HTML Display Block

    Below are the different examples given.

    Example #1

    This is a normal example showing how the HTML display block property going to be used in the HTML code is as follows:

    Code:

    
    <style>
    .block_demo{
    border: 2px solid red;
    width:50%;
    display:block;
    }
    </style>
    
    <h4 id="List-of-Color-Names">List of Color Names:</h4>
    <div class="block_demo">
    <ul>
    <li>Red</li>
    <li>Green</li>
    <li>Blue</li>
    <li>Orange</li>
    <li>Purple</li>
    <li>Pink</li>
    </ul>
    </div>
    <h4 id="List-of-Mobile-Brands">List of Mobile Brands:</h4>
    <div class="block_demo">
    <ol>
    <li>Apple</li>
    <li>SAMSUNG</li>
    <li>NOKIA</li>
    <li>MOTOROLA</li>
    <li>LENOVO</li>
    <li>OPPO</li>
    </ol>
    </div>
    
    

    Output:

    HTML Display Block

    Example #2

    In this example, we are going to create 3 equal blocks and show data in between them using the Display block as follows:

    Code:

    
    
    <title>HTML Display box</title>
    <style>
    #block1{
    height: 100px;
    width: 400px;
    background: orange;
    display: block;
    }
    #block2{
    height: 100px;
    width: 400px;
    background: white;
    display: block;
    }
    #block3{
    height: 100px;
    width: 400px;
    background: lightgreen;
    display: block;
    }
    .flag {
    margin-left:20px;
    font-size:40px;
    font-weight:bold;
    color:blue;
    }
    .demo {
    font-size:20px;
    margin-left:20px;
    }
    .main {
    margin:50px;
    text-align:center;
    border: 1px solid black;
    }
    </style>
    
    
    <div class="flag">National Flag of India</div>
    <div class="demo">Meaning of National Flag</div>
    <div class="main">
    <div id="block1">The saffron color of the flag indicates a symbol of courage and sacrifice. This is also known as Bhagwa color. It’s for renunciation . It represents fire. </div>
    <div id="block2">The white color of our flag represents honesty, peace, purity. It focus on importance of maintaining peace in the country.
    <img  src="/static/imghwm/default1.png" data-src="AC.png" class="lazy"   style="max-width:90%" alt="HTML Display Block" >
    </div>
    <div id="block3">The green color represents faith and chivalry. It’s for nature. It is a symbol of prosperity and life. It also used for representing auspiciousness of the Indian Motherland..</div>
    </div>
    
    

    Output:

    HTML Display Block

    Example #3

    This example includes elements like Header, footer, section, sidebar, etc. are as follows:

    Code:

    
    
    <title>HTML Display Block</title>
    <style>
    body {
    margin: 0;
    }
    .header {
    padding: 10px;
    text-align: center;
    background-color:cadetblue;
    color: white;
    }
    .navbar {
    overflow: hidden;
    background-color:darkkhaki;
    }
    .navbar a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 10px 10px;
    }
    .navbar a.right {
    float: right;
    }
    .navbar a:hover{
    background-color: #eee;
    color: black;
    }
    .row {
    display: flex;
    flex-wrap: wrap;
    }
    .section {
    flex: 10%;
    background-color: #f1f1f1;
    padding: 20px;
    }
    .main {
    flex: 80%;
    background-color: white;
    padding: 20px;
    }
    .footer{
    padding:3px;
    background-color:darkcyan;
    width:100%;
    }
    </style>
    
    
    <div class="header">
    <h1 id="HEADER-of-Webpage"> HEADER of Webpage</h1>
    </div>
    <div class="navbar">
    <a href="#">Home</a>
    <a href="#">About US</a>
    <a href="#">Services</a>
    <a href="#">Contact</a>
    <a href="#" class="right">SignUp</a>
    </div>
    <div class="row">
    <div class="section">
    <h2 id="Sidebar-comes-here">Sidebar comes here</h2>
    </div>
    <div class="main">
    <h2></h2>
    <p></p>
    <br>
    <div class="row">
    <div class="section" style="margin-top:-50px;">
    <h2 id="Example-of-section">(Example of section)</h2>
    </div>
    </div>
    </div>
    <div class="footer">
    <p>Footer</p>
    </div>
    </div>
    
    

    Output:

    HTML Display Block

    Conclusion

    From all the above information, we learned that the HTML display block property in HTML helps us to set our layout in the proper structure. Those blocks in the layout can be put in either vertical or horizontal directions, one after another. It include elements like

    ,
    ,
    .
    ,
    ,

    -

    , etc.

The above is the detailed content of HTML Display Block. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.