Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 8

Text Elements in HTML

Recommended resources

Hello! Welcome back.

In our last lesson, we built the fundamental skeleton of a webpage using the <html>, <head>, and <body> tags. You now have an index.html file that, while simple, is a complete and valid webpage.

Today, we're going to put some flesh on those bones. Our goal is to add headings, paragraphs, and other text elements to your webpage. This is how you'll add the visible content that your users will read. For your AI writing assistant project, this means adding a title, instructions, and eventually, a place to show the AI's output.

Structuring Content with Headings and Paragraphs

Think about any document you've ever readβ€”a news article, a book, a recipe. They all use titles, subtitles, and paragraphs to organize information and make it easy to read. In HTML, we do the same thing using heading and paragraph tags.

Headings: Creating a Hierarchy

Headings are used for titles. HTML gives us six levels, from <h1> to <h6>.

  • <h1> is for the most important, top-level heading. You should generally only have one <h1> per page.
  • <h2> is for a major sub-heading.
  • <h3> is for a sub-sub-heading, and so on, down to <h6>.

Using headings correctly isn't just about making text big or small; it's about giving your page a logical structure. This is incredibly important for search engines (like Google) and for users with visual impairments who use screen readers to navigate the page. This concept is called semanticsβ€”using HTML tags to describe the meaning of the content, not just its appearance.

Let's dive into an excellent article from MDN Web Docs that explains this concept.

Headings and paragraphs - Learn web development | MDN

This article explains why a logical structure with headings is crucial and introduces the best practices for using them.

Please read the first three sections: 'Headings and paragraphs', 'Implementing structural hierarchy', and 'Why do we need structure?'. Focus on understanding why using headings in the correct order is so important.

Paragraphs: The Building Blocks of Text

For regular blocks of text, we use the paragraph tag, <p>. It's one of the most common tags you'll use.

A key thing to understand is that browsers ignore extra spaces and line breaks in your HTML code. If you want to start a new paragraph, you must use a new <p> tag.

This video provides a great visual demonstration of both headings and paragraphs in action.

#7 - Paragraphs and Headings - HTML Full Tutorial for Beginners

This tutorial from Dev Dreamer clearly demonstrates how to use heading and paragraph tags and explains the important concept of whitespace insensitivity in HTML.

Watch the sections on paragraphs (00:29 - 01:52) and headings (03:08 - 06:29). Pay close attention to how multiple <p> tags are needed to create separate paragraphs.

This image provides a perfect summary of what we've just discussed, showing the code on the left and the browser output on the right.

HTML Text Elements Explained Thumbnail
This image shows how `<h1>`, `<h2>`, and paragraph text in an HTML file are rendered as structured, visible content in a web browser.

Let's Code: Adding Content to Your Page

Now, open your index.html file. Let's replace the single line of text in the <body> with a proper title and description for your future app.

Modify your <body> section to look like this:

<body>
  <h1>AI Writing Assistant</h1>
  <p>This tool will help you improve your writing. You can use it to check grammar, summarize text, and more.</p>
</body>

After saving the file, open it in your browser (or refresh the page if it's already open). You should now see a large, bold title and a paragraph of text below it.

Test your understanding!

Imagine you want to add a new section to your page titled "Features" and then list one of the features in a paragraph below it. Which tags would you use for the "Features" title and the text describing it?

Show answer

You would use an <h2> tag for the "Features" title, since it's a sub-heading under the main <h1> title of the page. Then you would use a <p> tag for the description that follows.

For example:

<h2>Features</h2>
<p>Check your text for grammar and spelling mistakes.</p>

Adding More Text Elements

Besides headings and paragraphs, HTML provides other useful tags for formatting text.

Lists: Unordered and Ordered

When you have a list of items, like the features of your app, it's best to use list tags. The most common is the unordered list (<ul>), which creates a bulleted list. Each item in the list is wrapped in a list item tag (<li>).

Learn HTML & CSS - Coding Basics: Intro to HTML Syntax

This article from Noble Desktop provides a very clear, step-by-step guide to creating a bulleted list.

Read the section titled 'Lists'. It clearly explains the <ul> and <li> tags.

Let's add a list of planned features to your index.html. Add this code below the paragraph you already have:

<h2>Planned Features</h2>
<ul>
  <li>Grammar & Spelling Correction</li>
  <li>Text Summarization</li>
  <li>Style Improvement</li>
</ul>

Save and refresh your browser. You'll see a new sub-heading and a neat, bulleted list.

Emphasis: Bold and Italic

Sometimes you need to make a word or phrase stand out. For this, you can use:

  • <strong>: For text that has strong importance. Browsers typically render this as bold.
  • <em>: For text that you want to emphasize. Browsers typically render this as italic.

Like headings, these tags have semantic meaning. <strong> tells screen readers to read the text with strong emphasis.

Let's see how to use them.

Learn HTML & CSS - Coding Basics: Intro to HTML Syntax

The same Noble Desktop article also covers how to make text bold and italic in a semantically correct way.

Now, read the section titled 'Strong & Em (Bold & Italic)'.

Let's update our first paragraph to include these. We can make the word "improve" stand out.

Modify your first <p> tag like this:

<p>This tool will help you <strong>improve</strong> your writing. You can use it to check grammar, summarize text, and <em>more</em>.</p>

Save and refresh. You will see "improve" is now bold and "more" is italic.


Summary and Next Steps

Fantastic work! You've taken a blank page and given it a clear, readable structure. This is a huge step forward.

Key Takeaways from this lesson:

  • Use <h1> through <h6> to create a logical hierarchy for your content. Always start with one <h1>.
  • Use the <p> tag to wrap paragraphs of text. Remember that browsers ignore whitespace in your code.
  • Use <ul> and <li> to create bulleted lists.
  • Use <strong> and <em> to add semantic importance or emphasis to your text.

Your index.html file should now look something like this:

<!DOCTYPE html>
<html>
  <head>
    <title>My First Web App</title>
  </head>
  <body>
    <h1>AI Writing Assistant</h1>
    <p>This tool will help you <strong>improve</strong> your writing. You can use it to check grammar, summarize text, and <em>more</em>.</p>

    <h2>Planned Features</h2>
    <ul>
      <li>Grammar & Spelling Correction</li>
      <li>Text Summarization</li>
      <li>Style Improvement</li>
    </ul>
  </body>
</html>

In our next lesson, we will move on to a critical part of our application: getting input from the user. You will learn how to create a web form with a text area and a submit button, which will be the first step in building the interface for your AI tool.