Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • JavaScript
  • Toggle search form

HTML Block and Inline Elements

Posted on March 4, 2023April 1, 2023 By shani No Comments on HTML Block and Inline Elements

HTML elements can be broadly classified into two categories: block-level elements and inline elements.

  1. Block-level Elements: Block-level elements are elements that take up the entire width of their parent element, and create a new line before and after the element. Examples of block-level elements include <div>, <p>, <h1>-<h6>, <ul>, <ol>, <li>, <table>, <form>, etc.
  2. Inline Elements: Inline elements are elements that only take up the necessary width of their content, and do not create a new line before or after the element. Examples of inline elements include <span>, <a>, <strong>, <em>, <img>, <input>, <label>, <select>, etc.

Here’s an example to illustrate the difference between block-level and inline elements:

<!DOCTYPE html>
<html>
<head>
	<title>Block and Inline Elements</title>
	<style>
		.block {
			background-color: lightgray;
			padding: 10px;
			margin-bottom: 10px;
		}

		.inline {
			background-color: lightblue;
			padding: 10px;
			margin-right: 10px;
		}
	</style>
</head>
<body>
	<div class="block">This is a block-level element</div>
	<span class="inline">This is an inline element</span>
	<span class="inline">This is another inline element</span>
	<p class="block">This is another block-level element</p>
	<a class="inline" href="#">This is an inline link</a>
	<a class="inline" href="#">This is another inline link</a>
</body>
</html>

In this example, the <div> and <p> elements are block-level elements, while the <span> and <a> elements are inline elements. The CSS is used to style the elements differently based on their type. The block-level elements have a light gray background and a margin-bottom of 10 pixels, while the inline elements have a light blue background and a margin-right of 10 pixels.

HTML

Post navigation

Previous Post: HTML other lists
Next Post: HTML class Attribute

Leave a Reply Cancel reply

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

HTML Tutorial

  • HTML History
  • HTML Editors
  • What is an HTML Element?
  • HTML Attributes
  • HTML Headings
  • HTML Paragraphs
  • HTML Styles
  • HTML Text Formatting
  • HTML Quotation and Citation Elements
  • HTML Comments
  • HTML Colors
  • HTML Styles – CSS
  • HTML Links
  • HTML images
  • HTML Favicon
  • HTML Tables
    • HTML Table Colgroup
    • HTML Table Colspan and Rowspan
    • HTML Table Headers
    • HTML Table Padding and Spacing
    • HTML Table Sizes
    • HTML Table Styling
  • HTML List
  • HTML Ordered Lists
  • HTML Unordered List
  • HTML other lists
  • HTML Block and Inline Elements
  • HTML class Attribute
  • HTML id Attribute
  • HTML Iframes
  • HTML JavaScript
  • HTML File Paths
  • HTML – The Head Element
  • HTML Layout Elements and Techniques
  • HTML Responsive Web Design
  • HTML Computer Code Elements
  • HTML Semantic Elements
  • HTML Style Guide
  • HTML Entities
  • HTML Symbols
  • HTML Emojis
  • HTML Encoding (Character Sets)
  • HTML Uniform Resource Locators(URL)
  • HTML Versus XHTML
  • HTML Forms
  • HTML Form Attributes
  • HTML Form Elements
  • HTML Form Target Attribute
  • HTML Input Attributes
  • HTML Input form Attributes
  • HTML Input Types
  • HTML Canvas Graphics
  • HTML SVG Graphics
  • HTML Multimedia
  • HTML Video
  • HTML Audio
  • HTML Plug-ins
  • HTML YouTube Videos
  • HTML Geolocation API
  • HTML Drag and Drop API
  • HTML Web Storage API
  • HTML Web Workers API
  • HTML SSE API
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme