Block-and-Inline-Elements
Block-and-Inline-Elements
Topperworld.in
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.
Block elements
They consume the entire width available irrespective of their sufficiency.
They always start in a new line and have top and bottom margins.
It does not contain any other elements next to it.
©Topperworld
HTML
8) <table>: This tag is used for including the tables in the webpage when
there is a need for tabular data.
7. <aside>: This tag is used to mention details of the main content aside.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
p { background-color: #8A55; }
</style> </head>
<body>
<p>This paragraph is a block
level element; its background has been colored to display the
paragraph's parent element.</p>
</body>
</html>
©Topperworld
HTML
Output:
Inline elements
Inline elements occupy only enough width that is sufficient to it and
allows other elements next to it which are inline. Inline elements don’t
start from a new line and don’t have top and bottom margins as block
elements have.
<br>: This tag is used for mentioning line breaks in the webpage
wherever needed.
<script> : This tag is used for including external and internal JavaScript
codes.
<input>: This tag is used for taking input from the users and is mainly
used in forms.
<img>: This tag is used for including different images in the webpage
to add beauty to the webpage.
©Topperworld
HTML
Example:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
.highlight{
background-color:#efefef}
</style>
</head>
<body>
<div>It is a demo span <span class="highlight">inline
element</span>;
whose span is an highlighted with a grey color indicatin
g that it is an inline tag
</div>
</body>
</html>
Output:
©Topperworld
HTML
Example:
<!DOCTYPE html>
<html>
<head>
<style>
span.b {
display: inline-block;
width: 100px;
height: 100px;
padding: 5px;
color:white;
border: 1px solid blue;
background-color: blue;
}
</style>
</head>
<body>
<div>This is an example of inline-
block element with a span colored as blue <span class="b">I
nline-Block</span> </div>
</body>
</html>
Output:
©Topperworld
HTML
Inline elements occupy only Block Elements occupy the full width
sufficient width required. irrespective of their sufficiency.
Inline elements don’t have top Block elements have top and bottom
and bottom margin margin.
©Topperworld