Omega
last year
Omegacountry asked

What happens if you mix different HTML tags like this: <h1> hello <p1>hello world</p1></h1>

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

When you write

hello hello world

, you'll be mixing valid HTML tags with invalid ones, which can cause unexpected behavior in your browser.

Firstly,

is a valid HTML tag that defines the largest heading, commonly used for main titles or titles in a document. Tagging "hello" within the

will appropriately make it appear as a large heading.

However, is not a valid HTML tag. The correct tag for paragraphs is

.

Browsers tend to be forgiving and may try to interpret the code as best as they can, often treating unknown tags like as just normal text:

  • The word "hello" will be shown as a large heading.

  • "hello world" might appear as plain text right after "hello", still within the heading tag without any paragraph styling.

If you intended to have a paragraph inside the heading, use

instead:

hello

hello world

But be careful, nesting a

inside an

is not standard practice, and it might still lead to formatting confusion. Typically, paragraphs should stand alone or be placed within sections or divs, but not headings.

Hope this helps! Feel free to ask more questions if you’re curious about different HTML tags and their usage.

HTML
This question was asked as part of the Learn HTML course.