HTML Block And Inline Elements - GeeksforGeeks

Skip to content geeksforgeeks
  • Tutorials
    • Python Tutorial
      • Python Data Types
      • Python Loops and Control Flow
      • Python Data Structures
      • Python Exercises
    • Java
      • Java Programming Language
        • OOPs Concepts
      • Java Collections
      • Java Programs
      • Java Interview Questions
      • Java Quiz
      • Advance Java
    • Programming Languages
    • System Design
      • System Design Tutorial
    • Interview Corner
    • Computer Science Subjects
    • DevOps
    • Linux
    • Software Testing
    • Databases
    • Android
    • Excel
    • Mathematics
  • DSA
    • Data Structures
      • Linked List
      • Tree
    • Algorithms
      • Analysis of Algorithms
      • Searching Algorithms
      • Sorting Algorithms
    • Practice
      • Company Wise Coding Practice
      • Practice Problems Difficulty Wise
      • Language Wise Coding Practice
      • Curated DSA Lists
    • Company Wise SDE Sheets
    • DSA Cheat Sheets
    • Puzzles
  • Data Science
    • Data Science Packages
    • Data Visualization
    • Data Analysis
  • Web Tech
    • Web Development Using Python
      • Django
      • Flask
    • Cheat Sheets
  • Courses
    • DSA Courses
    • Programming Languages
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
  • HTML Tutorial
  • HTML Introduction
  • HTML Editors
  • HTML Basics
  • HTML Comments
  • HTML Elements
  • HTML Attributes
  • HTML Headings
  • HTML Paragraphs
  • HTML Text Formatting
  • HTML Quotations
  • HTML Colors
  • HTML Links Hyperlinks
  • HTML Images
  • HTML Favicon
  • HTML Tables
  • HTML List

    • HTML Lists
    • HTML Ordered Lists
    • HTML Unordered Lists
    • HTML Description Lists
  • HTML Block and Inline Elements
  • HTML Iframes
  • HTML File Paths
  • HTML Layout
  • HTML Computer Code Elements
  • HTML5 Semantics
  • HTML Entities
  • HTML Symbols
  • HTML Emojis
  • HTML Charsets
  • HTML URL Encoding
  • HTML Forms
  • HTML Responsive Web Design
  • HTML Video
  • HTML Examples
  • HTML Graphics

    • SVG Tutorial

    HTML Tutorial References

    • HTML Tags - A to Z List
    • HTML Attributes Complete Reference
    • HTML Global Attributes
    • HTML5 Complete Reference
    • HTML5 MathML Complete Reference
    • HTML DOM Complete Reference
    • HTML DOM Audio/Video Complete Reference
    • SVG Element Complete Reference
    • SVG Attribute Complete Reference
    • SVG Property Complete Reference
    • HTML Canvas Complete Reference
  • HTML Exercises, Practice Questions and Solutions
HTML Block and Inline Elements Last Updated : 17 Jan, 2024 Improve Improve Like Article Like Save Share Report

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 href="https://www.geeksforgeeks.org/" alt="GeeksforGeeks"> official</a> website for the articles on various courses. </body> </html>

 Output:

Block & Inline Elements

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

author apeksharustagi1998 Follow Improve Previous Article HTML Description Lists Next Article HTML Iframes

Please Login to comment...

Similar Reads

What is the difference between display: inline and display: inline-block in CSS? The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If we need to display the elements that are laid out a 4 min read What is the difference between inline-flex and inline-block in CSS? The display property specifies how an element should be displayed on a webpage. There can be many values, related to this property in CSS. Inline-block and inline-flex are two such properties. Although there are several values that this property can have, to understand the aforementioned, let us first look into three other values: inline, block, an 3 min read How display: inline is different from display: inline-block in CSS ? In this article, we will know about the display property in CSS, along with understanding the 2 different property values for display property, i.e., display: inline &amp; display: inline-block properties, &amp; will understand their basic differences &amp; implementation through the examples. The display property facilitates setting the element by 3 min read Difference between block elements and inline elements The inline and block elements of HTML are one of the important areas where web developers often get confused because they were unable to know which are inline and block elements which may cause clumsiness in a webpage in case he assumes some element to be a block but it is an inline element which causes next element comes next to it. So let us see 5 min read How to remove the space between inline-block elements? To remove space between inline-block elements in CSS, ensure no whitespace or line breaks exist in HTML between elements. Alternatively, set the font-size of the parent to 0 and reset for elements, or apply a negative margin to elements. This ensures elements align seamlessly without unwanted spacing. There are two methods to remove the space betwe 3 min read How to prevent inline-block divs from wrapping ? The display: inline-block; is a layout property in CSS that does not add a line break after the element. As a result, the elements can sit next to each other. The major difference between display: inline; and display: inline-block; is that, display: inline-block; also allows us to set the width and height of the element. We can prevent inline-block 5 min read Primer CSS Inline block grids Primer CSS is a free open-source CSS framework that is built with the GitHub design system to provide support to the broad spectrum of Github websites. It creates the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approa 2 min read CSS Inline-block CSS Inline-block permits the addition of the width and height on the element. This property is used to display an element as an inline element (like &lt;span&gt;). The height and width properties are not affected on display: inline; property. It allows only the left and right sides of margins, not the top, and bottom. This property is commonly used 3 min read How to make Inline-Level element into Block-Level Element? To change an Inline-level Element into a Block-level Element, you can use the display property in CSS. The display property allows you to specify the type of box used for an HTML element's layout. Here's how you can make an inline-level element into a block-level element: Using display: block;This CSS rule will apply the display: block; property to 1 min read Inline HTML Helper - HTML Helpers in ASP.NET MVC HTML Helpers are methods that returns HTML strings. These are used in the view. In simple terms, these are C# methods that are used to return HTML. Using HTML helpers you can render a text box, an area, image tag, etc. In MVC we have many built-in HTML helpers and we can create custom helpers too. Using HTML helpers a view can show model properties 2 min read View More Articles Article Tags :
  • HTML-Basics
  • HTML
  • Web Technologies
Like three90RightbarBannerImg Explore More We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It ! Lightbox Improvement Please go through our recently updated Improvement Guidelines before submitting any improvements. This article is being improved by another user right now. You can suggest the changes for now and it will be under the article's discussion tab. You will be notified via email once the article is available for improvement. Thank you for your valuable feedback! Suggest changes Please go through our recently updated Improvement Guidelines before submitting any improvements. Suggest Changes Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal. geeksforgeeks-suggest-icon Create Improvement Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all. geeksforgeeks-improvement-icon Suggest Changes Suggestion[CharLimit:2000] Create Improvement

What kind of Experience do you want to share?

Interview Experiences Admission Experiences Career Journeys Work Experiences Campus Experiences Competitive Exam Experiences Can't choose a topic to write? click here for suggested topics Write and publish your own Article

Từ khóa » Html Css Block Elements