Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,236 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.