#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
HTML Fundamentals

HTML Blocks

HTML elements fall into two broad groups based on how they sit on the page: block-level elements, which start on a new line and stretch across the full width available, and inline elements, which sit within a line of text and take only as much width as their content. Knowing which is which explains why some elements stack and others flow side by side.

How block and inline elements behave

BehaviourBlock-levelInline
Starts on a new lineYesNo
Default widthFull width of the parentWidth of its content
Width and height propertiesRespectedIgnored
Vertical marginPushes neighbours awayDoes not affect line spacing
Examplesdiv, p, h1–h6, ul, section, formspan, a, strong, em, img, code

Strictly speaking, modern HTML describes content categories rather than "block" and "inline", and the visual behaviour comes from the CSS display value. In everyday work, though, the two labels are still the clearest way to think about it.

The div and span containers

Two elements exist purely to group other content and carry no meaning of their own. <div> is the generic block container, and <span> is the generic inline one. You reach for them when you need a hook for CSS or JavaScript and no meaningful element fits.

<div class="notice">
  <h2>Library timings</h2>
  <p>
    Open from <span class="time">9 AM</span> to
    <span class="time">6 PM</span>, Monday to Saturday.
  </p>
  <p>Sunday: <strong>closed</strong>.</p>
</div>

Here the div groups the whole notice so it can get a border and padding, while each span lets you colour the times without breaking the sentence onto new lines.

Prefer meaningful elements over plain divs

A page built entirely from divs works visually, but browsers, search engines and screen readers learn nothing about its structure. HTML5 added semantic block elements that describe their role: <header>, <nav>, <main>, <section>, <article>, <aside> and <footer>. Use these first, and fall back to div only for grouping that is purely for styling. These elements are the building blocks of the layouts in the next lesson.

Nesting rules that catch beginners

Not every element can go inside every other one:

  • A <p> cannot contain block elements like <div>, <ul> or another <p>. If you write one inside, the browser closes the paragraph early, and your CSS suddenly stops matching what you expected.
  • Inline elements such as <span> should not wrap block elements. The exception is <a>, which is allowed to wrap a whole card in HTML5, as long as nothing interactive is inside it.
  • List items, <li>, belong directly inside <ul> or <ol>.

A validator or the browser's element inspector quickly shows when the browser has silently rearranged your markup.

Changing the behaviour with CSS

Block or inline is just a default. CSS can change it: display: block makes a link fill its row, display: inline-block lets an element sit in a line while still accepting width, height and vertical padding, and display: flex turns a container into a flexible layout. The HTML element you choose should reflect meaning; CSS takes care of the look.

The habit to keep: pick elements for what the content is, use div and span only when nothing better exists, and adjust appearance with display.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course