Super simple but don't know: nested rules for HTML tags

Source: Internet
Author: User

There are many XHTML tags: div, ul, Li, DL, DT, DD, H1~H6, p, a, Addressa, span, strong ... When we use these tags to build the page structure, it is possible to embed them infinitely, but, nested also need to have certain rules, can not be arbitrarily nested by their own personal habits, then the HTML tag nested rules?

First, HTML tags include block-level elements (blocks), inline elements (inline)

1, block-level elements

Generally used to build Web site architecture, layout, hosting content ... It includes the following tags:

Address, blockquote, center, dir, Div, DL, DT, DD, fieldset, form, H1~h6, HR, Isindex, menu, Noframes, NoScript, OL, p, pre, Table, UL

2. Embedded elements

Some of the details or parts of the site are generally used to "emphasize, differentiate style, superscript, subscript, anchor" and so on, these tags are embedded elements:

A, ABBR, acronym, B, BDO, big, BR, cite, code, DFN, EM, font, I, IMG, input, KBD, label, Q, S, Samp, select, small, span, strike, Strong, Sub, SUP, textarea, TT, U, var

Ii. nested rules for HTML tags

1. Block elements can contain inline elements or some block elements, but inline elements cannot contain block elements, which can contain only other inline elements:


<a href= "#" ><span></span></a>--to


2. Block-level elements cannot be placed in <p>:



3. There are several special block-level elements that can contain only inline elements and no longer contain block-level elements, which are the following special tags:

H1, H2, H3, H4, H5, H6, p, DT

4. Li can contain div tags-this one is not necessarily listed separately, but many people on the internet have some doubts about it, here slightly explain:

Li and div tags are loaded contents of the container, equal status, no level of points (for example: H1, H2 such a hierarchical system ^_^), you know, Li Tag even its parent UL or OL can be accommodated, why would someone think that Li will not fit a div? Do not see Li so stingy, don't look at Li is very thin, in fact, Li's mind is very big drop ...

5. Block-level elements are tied to block-level elements, inline elements and inline elements:


<div><a href= "#" ></a><span></span></div>--to


Super simple but don't know: nested rules for HTML tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.