HTML | Block and Inline Elements
Every element in HTML has a default display value which depends upon the element type. Block or inline are the default display value for the most of the elements.
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.
- 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-1:
<!DOCTYPE html><html><body><style>body {text-align: center;}h1 {color: green;}</style><!-- Div element. --><divstyle="background-color:black;color:white;padding:20px;"><h1>GeeksforGeeks</h1><h3>GeeksforGeeks is a scienceportal for geeks.</h3><h3>You can give reviews as well ascontribute posts on this portal.</h3></div></body></html>chevron_rightfilter_noneOutput:
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 necessary width.
- span element: The span element 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-2:
<!DOCTYPE html><html><style>body {text-align: center;}h1 {color: green;}</style><body><!-- Sapn element. --><h1>Geeks<spanstyle="color:red">for</span>Geeks</h1></body></html>chevron_rightfilter_noneOutput 2:

Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Safari
- Opera
Recommended Posts:
- How to remove the space between inline-block elements?
- What is the difference between display: inline and display: inline-block in CSS?
- How to write a:hover in inline CSS?
- How to write an inline IF statement in JavaScript ?
- Displaying inline and multiline blocks of code using Bootstrap
- How to stop event propagation with inline onclick attribute in JavaScript ?
- Where is an object stored if it is created inside a block in C++?
- HTML | Elements
- HTML | Computer Code Elements
- How to determine the content of HTML elements overflow or not ?
- Hide or show elements in HTML using display property
- Hide or show HTML elements using visibility property in JavaScript
- HTML Course | Structure of an HTML Document
- HTML Course | Basics of HTML
- HTML | DOM HTML Object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



