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) Storing and Tracking Information with Variables The Variable Challenge Solution

what is the purpose of or why do we use <h2> or </h2>?

what is the purpose of <h2> and </h2> at the beginning and end of the sentence?

2 Answers

Davinderpal Rehal
Davinderpal Rehal
5,631 Points

The purpose is mostly just to indicate to the browser the text that follows should be treated like a h2 and to tell it exactly how much of the text is to be considered a h2 there needs to be an ending to it.

What you need to understand that to a browser

<h2>Title of the page</h2>
<p>A paragraph in the page.</p>

is the same as saying

<h2>Title of the page</h2><p>A paragraph in the page.</p>

which is the same as

<h2>
Title
of
the
page
</h2>
<p>A                paragraph      in          the        page</p>

That it to say the spacing means nothing to it so the best way of specifying how much text needs to go into a particular tag the opening and closing tags need to be specified.

<h2> is a "opening" HTML tag meaning "Heading" it has 6 different sizes. <h1> being the biggest and <h6> being the smallest. With MOST HTML tags you need to add a 2nd "closing" tag to complete the line of code. The closing tag looks like the opening tag except with a / . Like this </h2>. In this case... he opened the <h2> tag on one line, and closed it </h2> on another line. Then he concatenated them (added together) to create the full line.

tal Shnitzer
tal Shnitzer
Courses Plus Student 5,242 Points

so actually he did it to get larger sentence size? because it works w/o any HTML tag as well.