HTML Inline-Block
HTML has another type of element called Inline Block Elements. It is only the space occupied and bounded by each and every tag called by defined elements instead of breaking the HTML contents flow. The block-level elements feature mainly we consider as
Syntax of HTML Inline-Block
The basic syntax is followed below:
Syntax:
<html> <body> <p><span> ---some html codes ---</span> </p> </body> </html>
The above codes are basic syntax for writing the inline-block elements in html. We have used some sets of pre-defined inline-block elements below.
The above tags are pre-defined html inline elements based on the user requirements in the html mainly; we will focus on tag in html inline-block elements. We all know block-level elements always start a new line and take up with full width for given variables, but inline elements do not start a new line. Also, it takes less width when compared to block-level elements, but it has necessary to declare width in the html inline elements. The inline elements will be declared on the inside of the paragraph elements. The element is often used in the container as some text and has no specific required attributes, but the given css style, class, and ids are common when the element is used together with css in some style parts of the text.
How to Create HTML Inline Block?
- As discussed in earlier articles, we have created the HTML inline-block elements in the block-level elements. The HTML elements only take the user to allot the given necessary spaces and appear next to each other on the same line of the HTML tags. We can’t control the height and width of the HTML elements; it is the properties of the inline elements.
- The CSS style attributes called display: inline disregards the padding and margin settings when they need; it will allow the padding and margin values in the HTML. It contains only inline elements and makes block elements appear in a single line with the help of settings like display: inline. We can use CSS styles to set div tags at 50% width if you don’t want to minimize the HTML codes.it is a CSS solution for inline-block elements.
- Sometimes we can use white space:no-wrap is the parent container; it will allow the tag to display in each div inline-block as we expected without chaining the divs together is also referred to as a nested div tag. We have discussed some inline-block elements that will be used for creating layouts with the help of CSS styles.
- Suppose we use two divs tags in HTML displayed with the inline-block elements settings in CSS styles. We can set the width of each tag as 50%, but the second div tag falls below the first div tag.
Code:
<html> <head> section { background: green; box-sizing: border-box; padding: 150px; } div { box-sizing: border-box; display: inline-block; height: 100px; padding: 54px; text-align: center; width: 53%; } .green { background: lightgreen; } .black { background: black; } </head> <body> <span style="border: 2px lightgreen"> </span> <section> <div class="green">Width: 40%</div> <div class="black">Width: 60%</div> </section> </body> </html>Explanation of the above code: In the above codes, we have set the width for two div tags; each will be 50%, and the display attributes will be inline-block. The expected output will vary because the two div tags’ width is 50%, so will change any of the tag values should be 51% or 49%. Still, it is not a good practice and also not enough for the HTML element space; it needs at least 50% because inline elements respect with word spacing between the two div tags in HTML.
We can also use some borders and padding styles in the HTML div tags; it will highlight the web pages more effectively. We use
tag called block-level elements for the above codes. We use the tag as the inline element tag; we will use some contents inside the tags that will be required on the web page. Examples to Implement in Inline-Block
We will discuss the below examples.
Example #1
Code:
<html> <body> <p>Sample <span style="border:3px green">Welcome</span>To my domain</p> <p>Welcome to My Domain</p> </body> </html>
Output:

Example #2
Code:
<html> <head> <style> span.first { display: inline; width: 150px; height: 120px; padding: 8px; border: 3px blue; background-color: green; } span.second { display: inline-block; width: 140px; height: 110px; padding: 7px; border: 3px blue; background-color: green; } span.third { display: block; width: 103px; height: 110px; padding: 6px; border: 2px yellow; background-color: black; } </style> </head> <body> <div> Welcome to My Domain <span class="first">Welcome</span> <div> <div> Same Same <span class="second">Same Same</span> <div> <div> Welcome to My Domain <span class="third">Welcome</span> <div> </body> </html>Output:

Example #3
Code:
<html> <head> <style> .first { float:center; display: inline; width: 150px; height: 120px; padding: 8px; border: 3px blue; background-color: green; } .1{ clear:center; } </style> </head> <body> <div class="first"> <marquee> Welcome to My Domain</marquee> </div> </body> </html>Output:

Explanation of the above code: The first example will discuss the essential inline element called tag that will use for the web page; the second example will use span in the CSS style, and the same will be called in the tag in body sections each of the CSS styles will be defined in each span third example we will use some text values in the box-limit areas in the inline-block element features.
Conclusion
In Conclusion, partly based on the above topics, we have some ideas about inline-block elements in Html. We use both tag elements for their dependencies and features in user areas. However, IE and other browser versions may or may not support some tags.
The above is the detailed content of HTML Inline-Block. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
How to restrict file types for an upload input in HTML
Aug 24, 2025 am 02:57 AM
Use the accept attribute to limit the upload type of HTML file, such as accept="image/*" only allows images, accept=".pdf" only allows PDF, accept=".doc,.docx,.pdf,.txt" allows multiple specified types, and can combine JavaScript to verify file types to improve user experience, but security verification must be performed on the server side, because the accept attribute is not secure and the browser supports are different, and it is only used to improve availability rather than replace server verification.
How to disable a form element in HTML
Aug 30, 2025 am 08:45 AM
To disable HTML form elements, you can use the disabled attribute, which can prevent user interaction and the element value will not be submitted with the form. This attribute is of a Boolean type and can be directly added to form element tags such as input, textarea, select, or button. For example, it can also be dynamically controlled through JavaScript, such as document.getElementById("myInput").disabled=true. If the element cannot be edited but the value is still submitted, you should use the readonly attribute. The disabled attribute is simple and effective and widely supported.
How to use the HTML5 contenteditable attribute
Aug 23, 2025 am 09:55 AM
ThecontenteditableattributemakesHTMLelementseditablebyaddingcontenteditable="true"toelementslikediv,p,orh1–h6.2.UseJavaScripttoretrievecontentviainnerHTMLforformattedtextortextContentforplaintext.3.Listenforchangesusingtheinputeventtocaptur
How to add a favicon to your website with HTML5
Aug 27, 2025 am 02:35 AM
To add a website favicon correctly, first prepare a 32×32 or 64×64 pixel .ico, .png or .svg format icon file and name it favicon.ico, etc., place it in the website root directory or a specified path, and then use a clear statement in the HTML tag. For example: It is recommended to support multiple formats and devices at the same time, such as adding PNG different size versions, SVG icons, and Apple touch icons. Finally, clear the cache and test whether it displays normally, to ensure that the path is correct and the file is accessible. The entire process requires attention to the file format, path and compatibility to avoid loading failure.
What is the importance of the alt attribute for images in HTML5?
Aug 27, 2025 am 02:29 AM
Thealtattributeisessentialforaccessibility,SEO,anduserexperience;1.Itenablesscreenreaderstodescribeimagestovisuallyimpairedusers,ensuringcontentcomprehension;2.Itdisplaysfallbacktextwhenimagesfailtoload,maintainingcontext;3.ItimprovesSEObyhelpingsear
What is ARIA in HTML for accessibility?
Aug 27, 2025 am 04:57 AM
ARIAisneededtoenhancewebaccessibilityfordynamiccontentandcustomUIcomponentsthatlacknativeHTMLsemantics.1)ARIArolesdefineanelement’spurpose(e.g.,role="dialog").2)ARIApropertiesdescribecharacteristics(e.g.,aria-label,aria-describedby).3)ARIAs
What is the placeholder attribute's purpose in HTML5?
Aug 31, 2025 am 06:58 AM
Theplaceholderattributeprovidesashorthintininputfieldsthatdisappearswhentypingbegins;1.Itisusedinandelementstoshowexampletextlike"Enteryouremail";2.Thehintisdisplayedonlywhenthefieldisemptyandstyledfaintlybybrowsers;3.Itdoesnotreplacetheele
How does Content Security Policy (CSP) work with HTML5?
Aug 30, 2025 am 01:29 AM
CSPenhancesHTML5securitybydefiningtrustedcontentsourcestopreventXSS,clickjacking,andcodeinjection.1.Itrestrictsinlinescriptsandstylesbyblockingthemunless'unsafe-inline',nonces,orhashesareused.2.Itcontrolsexternalresourcesviadirectiveslikescript-src,i





