Inline & Block Elements In HTML
In HTML each element consist of start tag , content and end tag. Each element occupy space on the web page, and which determined by their display value defined by CSS display property. There are two display values – block and inline elements in HTML.
Block elements in HTML begin on a new line and occupy the complete horizontal space of its parent element and have the same height as the content, for Example – the div tag.
Inline elements in HTML do not begin from a new line and occupy space as required for its content, for Example -span, anchor , img tag.
Inline Elements in HTML
They do not force the text after them to a new line. An anchor ( link) , image, span are examples of inline elements . We can put several links or images, or span in a row, and they will display in a line.
They flow within the content, wrapping around other inline elements and text. Inline elements are often used for text-level styling and grouping small pieces of content.
Don’t have any effect of height and width property of an Inline elements . They typically cannot contain block-level elements but can be nested within other inline elements
Examples of inline elements:
<a> , <img>, <label>, <span>, <i>
// making paragraph inline -remember inline have no effect of height and width
p{
display:inline;
}
They typically start on a new line and take up the full available width of their parent container. Block elements create a “block” or a rectangular box on the web page. Block-level elements are used for structural components like headings, paragraphs, divs, lists (ul, ol), and more.
More examples
<div>
<p>
<h1> to <h6>
<ul> and <ol>
<li>
<table>
<form>
Block-level elements can have their width, height, margin, padding, and border properties adjusted. They can also contain other block-level and inline elements.
Document
Good understanding of inline and block element helps to create a web layout easily and rapidly. So for any layout creation in html and css display property plays major role, So make it more strong for become a successful web developer .
Recent Post
Var keyword in C#
- May 8, 2024
- 4 min read
What is Cloud Computing ? Definition &
- April 2, 2024
- 4 min read
Devika – An Open-Source AI Software Engineer
- March 27, 2024
- 3 min read