Geek Slack

Introduction to HTML
    About Lesson



    HTML Block and Inline Elements


    HTML Block and Inline Elements

    HTML elements can be categorized as either block-level elements or inline elements. Understanding the distinction between these types is crucial for creating well-structured web pages.

    1. Block-Level Elements

    Block-level elements start on a new line and take up the full width available. They often contain other block-level elements or inline elements.

    Common block-level elements include:

    • <div>
    • <p>
    • <h1> to <h6>
    • <ul> and <ol>
    • <blockquote>

    Example:

    Block-Level Heading

    This is a block-level paragraph. It starts on a new line and takes up the full width available.

    <div>
        <h2>Block-Level Heading</h2>
        <p>This is a block-level paragraph. It starts on a new line and takes up the full width available.</p>
    </div>

    2. Inline Elements

    Inline elements do not start on a new line and only take up as much width as necessary. They are typically used for formatting parts of text within block-level elements.

    Common inline elements include:

    • <span>
    • <a>
    • <img>
    • <strong> and <em>
    • <br>

    Example:

    This is a span element inside a paragraph. Here is a link and an important word.

    <p>This is a <span style="color: red;">span</span> element inside a paragraph. Here is a <a href="#">link</a> and an <strong>important</strong> word.</p>

    3. Inline Code Editor

    Try editing the code below to see the difference between block and inline elements in action.



    Conclusion

    Understanding the difference between block-level and inline elements is fundamental for structuring HTML documents. Block-level elements take up the full width available and start on a new line, while inline elements take up only as much width as necessary and do not start on a new line.