HTML ( Hypertext Markup Language ) elements historically were categorized as either "block-level" elements or "inline-level" elements. Since this is a presentational characteristic it is nowadays specified by CSS in the 流式布局 . Inline elements are those which only occupy the space bounded by the tags defining the element, instead of breaking the flow of the content. In this article, we'll examine HTML inline-level elements and how they differ from 块级元素 .

An inline element does not start on a new line and only takes up as much width as necessary.

Inline vs. block-level elements: a demonstration

This is most easily demonstrated with a simple example. First, some simple CSS that we'll be using:

.highlight {
  background-color:#ee3;
}
					

Inline

Let's look at the following example which demonstrates an inline element:

<div>The following span is an <span class="highlight">inline element</span>;
its background has been colored to display both the beginning and end of
the inline element's influence.</div>
					

在此范例中, <div> block-level element contains some text. Within that text is a <span> element, which is an inline element. Because the <span> element is inline, the paragraph correctly renders as a single, unbroken text flow, like this:

For looks, this CSS (not displayed in standard reading mode) is also used:

body {
  margin: 0;
  padding: 4px;
  border: 1px solid #333;
}
.highlight {
  background-color:#ee3;
}
					

Block-level

Now let's change that <span> into a block-level element, such as <p> :

<div>The following paragraph is a <p class="highlight">block-level element;</p>
its background has been colored to display both the beginning and end of
the block-level element's influence.</div>
					

The CSS (not displayed in standard reading mode) is also used:

body {
  margin: 0;
  padding: 4px;
  border: 1px solid #333;
}
.highlight {
  background-color:#ee3;
}
					

Rendered using the same CSS as before, we get:

See the difference? The <p> element totally changes the layout of the text, splitting it into three segments: the text before the <p> , then the <p> 's text, and finally the text following the <p> .

Changing element levels

You can change the visual presentation of an element using the 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 content model of the element. For example, even if the display span element is changed to "block" , it still would not allow to nest a div element inside it.

Conceptual differences

In brief, here are the basic conceptual differences between inline and block-level elements:

Content model

Generally, inline elements may contain only data and other inline elements. You can't put block elements inside inline elements.

格式化

By default, inline elements do not force a new line to begin in the document flow. Block elements, on the other hand, typically cause a line break to occur (although, as usual, this can be changed using CSS).

List of "inline" elements

The following elements are inline by default (although block and inline elements are no longer defined in HTML 5, use content categories instead):

  1. Allowing cross-origin use of images and canvas
  2. 使用 CSS 将颜色应用到 HTML 元素
  3. Block-level elements
  4. DASH Adaptive Streaming for HTML 5 Video
  5. 用于 HTML 的日期和时间格式
  6. 全局属性
    1. 全局属性
    2. accesskey
    3. autocapitalize
    4. class
    5. contenteditable
    6. contextmenu
    7. data-*
    8. dir
    9. draggable
    10. dropzone
    11. hidden
    12. id
    13. inputmode
    14. is
    15. itemid
    16. itemprop
    17. itemref
    18. itemscope
    19. itemtype
    20. lang
    21. part
    22. slot
    23. spellcheck
    24. style
    25. tabindex
    26. title
    27. translate
    28. x-ms-acceleratorkey
    29. x-ms-format-detection
  7. HTML 属性参考
    1. HTML 属性参考
    2. HTML attribute: accept
    3. HTML attribute: capture
    4. HTML attribute: crossorigin
    5. HTML attribute: max
    6. HTML attribute: maxlength
    7. HTML attribute: min
    8. HTML attribute: minlength
    9. HTML attribute: multiple
    10. HTML attribute: pattern
    11. HTML attribute: readonly
    12. HTML attribute: rel
    13. HTML attribute: required
    14. HTML attribute: size
    15. HTML attribute: step
    16. The HTML autocomplete attribute
    17. 被禁用
  8. HTML documentation index
  9. HTML 元素参考
    1. HTML 元素参考
    2. <a>: The Anchor element
    3. <abbr>: The Abbreviation element
    4. <acronym>
    5. <address>: The Contact Address element
    6. <applet>: The Embed Java Applet element
    7. <area>
    8. <article>: The Article Contents element
    9. <aside>: The Aside element
    10. <audio>: The Embed Audio element
    11. <b>: The Bring Attention To element
    12. <base>: The Document Base URL element
    13. <basefont>
    14. <bdi>: The Bidirectional Isolate element
    15. <bdo>: The Bidirectional Text Override element
    16. <bgsound>: The Background Sound element (obsolete)
    17. <big>: The Bigger Text element
    18. <blink>: The Blinking Text element (obsolete)
    19. <blockquote>: The Block Quotation element
    20. <body>: The Document Body element
    21. <br>: The Line Break element
    22. <button>: The Button element
    23. <canvas>: The Graphics Canvas element
    24. <caption>: The Table Caption element
    25. <center>: The Centered Text element (obsolete)
    26. <cite>: The Citation element
    27. <code>: The Inline Code element
    28. <col>
    29. <colgroup>
    30. <command>: The HTML Command element
    31. <content>: The Shadow DOM Content Placeholder element (obsolete)
    32. <data>
    33. <datalist>: The HTML Data List element
    34. <dd>: The Description Details element
    35. <del>: The Deleted Text element
    36. <details>: The Details disclosure element
    37. <dfn>: The Definition element
    38. <dialog>: The Dialog element
    39. <dir>: The Directory element (obsolete)
    40. <div>: The Content Division element
    41. <dl>: The Description List element
    42. <dt>: The Description Term element
    43. <element>: The Custom Element element (Obsolete)
    44. <em>: The Emphasis element
    45. <embed>: The Embed External Content element
    46. <fieldset>: The Field Set element
    47. <figcaption>: The Figure Caption element
    48. <figure>: The Figure with Optional Caption element
    49. <font>
    50. <footer>
    51. <form>
    52. <frame>
    53. <frameset>
    54. <h1>–<h6>: The HTML Section Heading elements
    55. <head>: The Document Metadata (Header) element
    56. <header>
    57. <hgroup>
    58. <hr>: The Thematic Break (Horizontal Rule) element
    59. <html>: The HTML Document / Root element
    60. <i>: the Interesting Text element
    61. <iframe>: The Inline Frame element
    62. <image>: The obsolete Image element
    63. <img>: The Image Embed element
    64. <input>: The Input (Form Input) element
    65. <ins>
    66. <isindex>
    67. <kbd>: The Keyboard Input element
    68. <keygen>
    69. <label>
    70. <legend>
    71. <li>
    72. <link>: The External Resource Link element
    73. <listing>
    74. <main>
    75. <map>
    76. <mark>: The Mark Text element
    77. <marquee>: The Marquee element (Obsolete)
    78. <menu>
    79. <menuitem>
    80. <meta>: The Document-level Metadata element
    81. <meter>: The HTML Meter element
    82. <multicol>: The HTML Multi-Column Layout element (Obsolete)
    83. <nav>: The Navigation Section element
    84. <nextid>: The NeXT ID element (Obsolete)
    85. <nobr>: The Non-Breaking Text element (obsolete)
    86. <noembed>: The Embed Fallback element (Obsolete)
    87. <noframes>: The Frame Fallback element
    88. <noscript>
    89. <object>
    90. <ol>: The Ordered List element
    91. <optgroup>
    92. <option>
    93. <output>: The Output element
    94. <p>: The Paragraph element
    95. <param>: The Object Parameter element
    96. <picture>: The Picture element
    97. <plaintext>: The Plain Text element (Deprecated)
    98. <pre>: The Preformatted Text element
    99. <progress>: The Progress Indicator element
    100. <q>: The Inline Quotation element
    101. <rb>: The Ruby Base element
    102. <rp>: The Ruby Fallback Parenthesis element
    103. <rt>: The Ruby Text element
    104. <rtc>: The Ruby Text Container element
    105. <ruby>
    106. <s>
    107. <samp>: The Sample Output element
    108. <script>: The Script element
    109. <section>: The Generic Section element
    110. <select>
    111. <shadow>: The obsolete Shadow Root element
    112. <slot>
    113. <small>: the side comment element
    114. <source>: The Media or Image Source element
    115. <spacer>
    116. <span>
    117. <strike>
    118. <strong>: The Strong Importance element
    119. <style>: The Style Information element
    120. <sub>: The Subscript element
    121. <summary>: The Disclosure Summary element
    122. <sup>: The Superscript element
    123. <table>: The Table element
    124. <tbody>: The Table Body element
    125. <td>: The Table Data Cell element
    126. <template>: The Content Template element
    127. <textarea>
    128. <tfoot>: The Table Foot element
    129. <th>
    130. <thead>: The Table Head element
    131. <time>
    132. <title>: The Document Title element
    133. <tr>: The Table Row element
    134. <track>: The Embed Text Track element
    135. <tt>: The Teletype Text element (obsolete)
    136. <u>: The Unarticulated Annotation (Underline) element
    137. <ul>: The Unordered List element
    138. <var>: The Variable element
    139. <video>: The Video Embed element
    140. <wbr>
    141. <xmp>
  10. HTML 参考
  11. 内联元素
  12. Link 类型
    1. Link 类型
    2. Link types: dns-prefetch
    3. Link types: manifest
    4. Link types: modulepreload
    5. Link types: noopener
    6. Link types: noreferrer
    7. Link types: preconnect
    8. Link types: prefetch
    9. Link types: preload
    10. Link types: prerender
  13. Microdata
  14. Microformats
  15. 采用 rel="preload" 预加载内容
  16. Quirks Mode and Standards Mode
  17. Using the application cache