HTML Block And Inline Elements - GeeksforGeeks
Có thể bạn quan tâm
HTML Block elements,are used to structure the main content of a webpage. They typically start on a new line and take up the full width of their container examples <div>, <p>, <h1> to <h6>, and <ul>, etc.
On the other hand, Inline elements are used within block-level elements to style or format specific parts of the content. They don’t start on a new line and only take up as much width as necessary for example include <span>, <a>, <strong>, and <em>.
Example: This example illustrates the use of the block-level element & inline element.
HTML <!DOCTYPE html> <html> <body> <div> GeeksforGeeks </div> Checkout the GeeksforGeeks <a alt="GeeksforGeeks" href="https://www.geeksforgeeks.org/"> official </a> website for the articles on various courses. </body> </html>Output:
In the above example, we have used the <div> tag that always starts in a new line & captures the full width available. We have used the inline element anchor tag <a>that is used to provide a link to a text. The inline element doesn’t start in a new line & captures only the space around the element.
Block Level Elements:
A block-level element always starts on a new line and stretches out to the left and right as far as it can i.e, it occupies the whole horizontal space of its parent element & the height is equal to the content’s height.
Supported tags:
- <address> Tag
- <blockquote> Tag
- <dd> Tag
- <Div> Tag
- <dl> Tag
- <dt> Tag
- <canvas> Tag
- <form> Tag
- <Heading> Tag
- <hr> Tag
- <li> Tag
- <main> Tag
- <nav> Tag
- <noscript> Tag
- <ol> Tag
- <pre> Tag
- <section> Tag
- <tfoot> Tag
- <ul> Tag
- Tables Tag
- HTML Paragraphs
- <Video> Tag
- <aside> Tag
- <article> Tag
- <figcaption> Tag
- <fieldset> Tag
- <figure> Tag
- <footer> Tag
- <header> Tag
div element:
The <div> element is used as a container for other HTML elements. It has no required attributes. Style, class, and id are the commonly used attributes.
Syntax:
<div>GFG</div>Example: The below code illustrates the implementation of <div> tag.
HTML <!DOCTYPE html> <html> <head> <title>Block-level Element</title> </head> <body> <div> <h1>GeeksforGeeks</h1> <h3>GeeksforGeeks is a science portal for geeks.</h3> <h3> You can give reviews as well as contribute posts on this portal. </h3> </div> </body> </html>Output:
Block Element
Inline Elements:
An inline element is the opposite of the block-level element. It does not start on a new line and takes up only the necessary width ie., it only occupies the space bounded by the tags defining the HTML element, instead of breaking the flow of the content.
Supported tags:
- <br> Tag
- <button> Tag
- <time> Tag
- <tt> Tag
- <var> Tag
- <a> Tag
- <abbr> Tag
- <acronym> Tag
- <b> Tag
- <cite> Tag
- <code> Tag
- <dfn> Tag
- <em> Tag
- <i> Tag
- <output> Tag
- <q> Tag,
- <samp> Tag
- <script> Tag
- <select> Tag
- <small> Tag
- <span> Tag
- <strong> Tag
- <sub> Tag
- <sup> Tag
- <textarea> tag
- <bdo> Tag
- <big> Tag
- <img> Tag
- <input> Tag
- <kbd> Tag
- <label> Tag
- <map> Tag
- <Object> tag
span element:
The <span> tag is used as a container for text. It has no required attributes. Style, class, and id are the commonly used attributes.
Syntax:
<span>GFG</span>Example: The below code illustrates the implementation of <span> tag.
HTML <!DOCTYPE html> <html> <head> <title>HTML span element</title> <style> body{ text-align:center; } h1{ color:green; } span{ color:red; } </style> </head> <body> <h1>Geeks <span> for</span> Geeks </h1> </body> </html>Output:
Inline Element
HTML Block and Inline Elements – FAQs
What is a block-level element?
Block-level elements start on a new line and take full width, like <div>, <p>, and <h1>. They stack vertically.
What is an inline element?
Inline elements flow within text without breaking the line, like <span>, <a>, and <img>. They take only the necessary width.
Can block-level elements contain inline elements?
Yes, block-level elements can contain inline elements, like <div><span>Text</span></div>.
Can inline elements contain block-level elements?
No, inline elements cannot contain block-level elements. Use block-level elements to wrap inline content.
Difference between inline and inline-block?
Comment More info Next Article HTML Iframes apeksharustagi1998 Follow Improveinline elements do not accept width/height. inline-block elements do, and they flow with text.
Từ khóa » Html Block Element Span
-
HTML Block And Inline Elements - W3Schools
-
Inline Elements - HTML: HyperText Markup Language | MDN
-
Block-level Elements - HTML: HyperText Markup Language | MDN
-
Block And Inline Elements
-
HTML - Blocks - Tutorialspoint
-
Inline And Block Elements In HTML - Scaler Topics
-
Difference Between Block Elements And Inline Elements
-
Block-Level And Inline Elements: The Difference Between
And ...Basic HTML: Block-level, Inline, And Organizational Elements
CSS Inline Vs Inline-Block Vs Block
Learn How Does Block Element Work In HTML? - EduCBA
Why
Nested In Leads For A Block Element? - Stack Overflow
Chapter 10: Differences Between
Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu