A block-level element always starts on a new line and stretches out to the left and right as far as it can .
Block-level element occupies the entire space of the parent (container) .
<div> and <p> tag are the best example of block Elements.
Common block-level elements: are <div>,<p>,<article>,<section>,<figure>,<footer> etc
<!DOCTYPE html>
<html>
<body>
<!-- Div element. -->
<div style="background-color:black;
color:white;
padding:20px;">
<h1>The developer Brains School</h1>
<h3>This is H3 heading and headings are also Block element.</h3>
</div>
</body>
</html>
HTML Inline elements are the opposite of the block elements .They do not start on a new line and takes full width.
Inline as the name says “included as a part of the main text and not as a separate section
Inline elements occupy the space as needed within the space defined by the main element
<!DOCTYPE html>
<html>
<style>
.highlight{
color: green;
}
</style>
<body>
<h2>We use span element to <span class="highlight">highlight</span>
text portion because span is inline element and don't break heading</h2>
</body>
</html>
You can change from display block level to Inline and Inline to block by using CSS display Property . For Example , by changing the value of display from "inline" to "block", you can tell the browser to render the inline element in a block box rather than an inline box, and vice versa. However, doing this will not change the category and the content model of the element. For example, even if the display of the span element is changed to "block", it still would not allow to nest a div element inside it.
div{
display: inline;
}
span{
display: block;
}
Share TDB SCHOOL
Share this E-Learning Website on social media platforms with your friends and followers