Introduction to HTML Block Elements

HTML Block Elements

Introduction to HTML Block Elements

Html is made up of various elements that will act as a building block of every web page. Each web page has different viewpoints, and different logics will be implemented from both the front end and back end. Html will have user-defined or customized requirements that will highlight web pages like CSS, bootstrap frameworks, etc. In CSS style for its purpose generally, the HTML elements are divided into two categories 1.block-level elements and 2.in-lne elements. We already discussed about previous article like span and div <span> element is used for in-line elements in HTML and <div> tag is used for block-level element in HTML.

Syntax:

<html>
<body>
<div>
----------codes------
----------------------
</div>
</body>
</html>

In general, each and every HTML tags its own predefined structures and features. Block-elements in HTML have a different set of tags we will use in the documents. Some of the tags listed below.

Tags:

<address>,<article><aside><blockquote><canvas><dd><div><dl><dt><fieldset><figcaption>
<figure>,<footer>,<form>,<h1>-<h6>,<header>,<hr>,<li>,<main>,<nav>,<noscript>,<ol>,<p>
<pre>,<section>,<table>,<tfoot>,<ul>,<video>

The above tags are predefined tags in html block elements; each tag will be used for different functionalities when we call the tags in html documents.Most probably we use <div> tags in block-level elements. Codes are general syntax for the block-level elements in HTML, and also we will use above mentioned predefined tags when it is needed; each tag will have independent and self-contained contents in HTML.

How does Block Element work in HTML?

It will use the CSS styles that have the formatting model; it will cover both the in-line and block elements. Most probably, it will take care of formatting block elements. Formatting block elements is one of the block-level elements in HTML. Every CSS elements look like forms; it contains a box; it has some components like content, padding, and border; these are the different components in CSS styles.

  • Content: It denotes the general content of the HTML elements such as text, pictures, and videos, etc.
  • Padding: It denotes any padding that has been covered into any contents by the format like padding-top,padding-left,padding-right,padding-bottom, etc. these are the properties.
  • Border: It denotes any borders in HTML contents and padding; borders will set by borders -top,borders-bottometc.

Block-elements want to set the margins and padding in HTML documents. Because in web pages they need proper alignments to view the users more attractive in nature. In something block-elements section contains margins it exists outside of an element, padding exists inside of elements it will surround the contents. If the elements required background color or images, they would be assigned to them, and the same will be displayed in both content and padding areas. Generally, margin areas are always transparent, and they display the background of the parent elements exception will occur if the parent element is not have n’t to which display properties are has been assigned to like body section, in which case any color or images displayed in both margin and padding areas or else margin is the distance between the outer edge of the HTML elements(both content and padding).

We also set the borders to highlight the web pages, include border colors, styles, width and margin. Same as being controlled by our end in both the appearance of the border around an element as well as the borders like all the types. CSS has its border-style property for enables the user to set their own customized border styles specified with values like none, solid, double, hidden, dotted, dashed, groove, ridge, inset, and outset. If we have aligned the documents with borders, we don’t specify any values mean the default value is none; it means no border is allotted for your page. All these border styles are included in the css1 version except hidden values which was added in the css2 version. Popular Course in this categoryHTML Training (12 Courses, 19+ Projects, 4 Quizzes)12 Online Courses | 19 Hands-on Projects | 89+ Hours | Verifiable Certificate of Completion | Lifetime Access | | 4 Quizzes with Solutions
4.5 (6,492 ratings)Course Price
₹6999 ₹41999
View Course


Related CoursesBootstrap Training (2 Courses, 6+ Projects)XML Training (5 Courses, 6+ Projects)CSS Training (9 Courses, 9+ Projects)

In Html 4 onwards, the div element is the block-level elements and is used to design the document with the specified divisions. Otherwise, div elements have no specific characteristics format, and also, the deprecated Align attributes in HTML can be used to a center or right side of its content; it’s a default in deprecated elements in HTML. In <div> tag was intended to take any format in CSS styles and div have the options like nested div tags and other elements nested with div element whatever styles, borders, and alignments we specified it would affect for those nested elements. Some basic codes for div tag with border, background image, and other user-defined format styles.

Code:

div.sample {width:150px;background:#FF0002;border:2px dotted black;padding:7px;}
div.sample ul {color:green;}

The above codes are samples to understand the CSS attributes and functionalities implemented with the div tag. We will discuss some basic examples in the below sections.

Examples of HTML Block Elements

Given below are the following examples:

Example #1

Code:

<html>
<head>
<style>
div.sample {width:150px;border:2px dotted black;padding:7px;}
div.sample ul {color:green;}
</style>
</head>
<body>
<div class="sample" style="color:black">
<p>Samples</p>
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Pineapple</li>
</ul>
</div>
</body>
</html>

Output:

BLOCK elements

Example #2

Code:

<html>
<head>
<style>
div.sample {width:150px;border:2px dotted black;padding:7px;}
div.sample ul {color:green;}
</style>
</head>
<body>
<p>Sample <span style = "color:green">green</span>
<span style = "color:black">black</span></p>
</body>
</html>

Output:

BLOCK elements

Example #3

Code:

<html>
<head>
<style>
.first {
background-color: green;
list-style-type: none;
text-align: center;
margin: 2;
padding: 2;
}
.second {
display: inline-block;
font-size: 30px;
padding: 23px;
}
</style>
</head>
<body>
<ul class="first">
<li><a href="#home">Home</a></li>
<li><a href="#aboutus">AboutUs</a></li>
<li><a href="#contactus">Contact Us</a></li>
</ul>
</body>
</html>

Output:

Home

In the above example, we see the different scenarios for the block-level elements first two examples, we use and align the menus or tabs or text values in the <div> and <span> tags.<span> is used for in-line elements, but <p> paragraph tag will use for blocking the text or values which is to be specified in the user-level areas. A final example will be used for the <nav> element in HTML for navigating the web pages with some block-level contents. We already discussed the working of block-level elements area; we specified some CSS properties are enabled with block-level attributes like background color,text-styles with list options,text-allignments, padding and margins,font-styles these are some attributes with values specified with the navigation web pages.

Conclusion

In the conclusion part, the HTML block elements will occupy the entire space for its parent elements (containers) to create the blocks. In general, browsers will display the block-level elements with the new line and full-width for both before and after the HTML elements. We can visualize the elements with boxes like a stack.

Recommended Articles

This is a guide to HTML Block Elements. Here we discuss the introduction, how does Block Element work in HTML, along with respective examples. You can also go through our other related articles to learn more –

  1. HTML Inline-Style
  2. HTML Align Center
  3. HTML Border Style
  4. Fieldset Tag in HTML

Leave a Comment

Your email address will not be published. Required fields are marked *