Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Build a Random Number Guessing Game

Adam Maley
Adam Maley
5,946 Points

Why is it necessary to add <p> html tags within quotations for dialogue boxes?

Why is it necessary to add <p> html tags within quotations for dialogue boxes?

Then sometimes I see him not using the "<p>Hello, press the" + " enter button.</p>" tags.

Couldn't I just type "Hello, press the enter button." ?

Ezell Frazier
Ezell Frazier
22,110 Points

The <p></p> tags are not necessary.

The tags exist for formatting purposes. When the results display on the HTML document, elements within the tags will have better line spacing.

However, I would recommend using the tags as a good practice.

4 Answers

Steven Parker
Steven Parker
218,695 Points

It depends on how the string is to be used.

If it is being written directly to the document, the tags cause an element to be created (in this case, a paragraph).

But in other cases the string might be used to update an existing element's text content, and in that case tags would not be used.

Andrew Dovganyuk
Andrew Dovganyuk
10,633 Points

Yeah it is for personal purposes :)

the <p> is added to make it a paragraph

I must admit I was slightly confused at first with this. Makes sense now.