liveBook · Manning

HTML tag

As explained in Build a Website with ChatGPT

An HTML tag is markup syntax that identifies the type, structure, or semantic boundaries of content in an HTML document.

An HTML tag is a short code in angle brackets that marks up an object on a web page, such as a heading, paragraph, list, or link. Tags tell the browser how page content is organized. For example, <h1> marks a first-level heading, while <p> marks a paragraph. section 2.2.1 section 7.2.6

Most tags work as a pair: a start tag opens the content and an end tag closes it. The end tag includes a slash. In <p>Hello!</p>, <p> begins the paragraph and </p> ends it; the words between them are the text you can safely change. section 2.2.1 section 12.2.5

A small heading and paragraph

<h1>Welcome</h1> <p>This is my home page.</p> Keep each opening tag with its matching closing tag. You can replace Welcome or the paragraph text, but do not delete the surrounding tags unless you also intend to remove that page object. section 3.4 section 4.4

Tags can also carry extra information. In <p class="entry-text">Entry text goes here.</p>, the class attribute names a set of CSS styles for that paragraph. An image tag can include an alt attribute whose value describes the image. Leave quotation marks around attribute values in place when editing them. section 5.4 section 10.8 section 5.3.2

Common practical uses include:

  • Mark a page title or subtitle with <h1>...</h1> or <h2>...</h2>. section 3.4
  • Add a paragraph with <p>, its text, and </p>. Some code editors add the closing tag automatically. section 9.6 section 12.2.5
  • Group a heading and paragraphs into a new section with <section>...</section>. section 6.4
  • Surround each list item with <li>...</li> so it remains a list item. section 9.6
  • Use <details>...</details> to duplicate an existing accordion-style entry, then edit its title, date, and text. section 5.4

Some tags point the browser to files rather than wrapping visible text. A <link rel="stylesheet" href="styles.css"> tag tells the browser where to find CSS. For images, HTML refers to a separately uploaded image file; the browser retrieves and displays it where the image tag appears. A <meta charset="utf-8"> tag helps special characters such as copyright symbols, em dashes, and curly quotation marks display properly. section 5.3.1 section 10.2 section 5.3.1

<!DOCTYPE html>
<html>
<head>
    <title>Pun Generator</title>                                                    #1   
    <style>
        body {                                                                      #2
            font-family: Arial, sans-serif;                                         #2
        }                                                                           #2
        #displayPun {                                                               #3
            font-size: 24px;                                                        #3
            margin-top: 20px;                                                       #3
        }                                                                           #3
    </style>
</head>
<body>
    <h1>Welcome to Pun Generator!</h1>                                              #4
    
    <button id="generatePun">Generate Pun</button>                                  #5
    
    <p id="displayPun"></p>                                                         #6
    <script>
        var puns = [                                                                #7
            "Time flies like an arrow; fruit flies like a banana.",                 #7
            "I used to be a baker because I kneaded dough.",                        #7
            "I used to play piano by ear, but now I use my hands.",                 #7
            // Add the rest of the 50 puns here...                                  #7
        ];    
        document.getElementById("generatePun").
addEventListener("click", function() {                                              #8
            var randomPunIndex = Math.floor(Math.random() * puns.length);           #8
            document.getElementById("displayPun").innerText = puns[randomPunIndex]; #8
        });                                                                         #8
    </script>
</body>
</html>

Inspect the listing to see tags working together: the title in the browser tab, a page heading, a button, and an empty paragraph identified for displaying a pun. section 2.2.1

When customizing generated HTML, start with small edits: change text between existing tags, copy a complete section or entry when you need another one, and then revise the copied text. Matching tags matter: deleting or changing one by accident can prevent the intended heading, paragraph, list item, or section from rendering properly. section 6.4 section 7.4.3

A useful prompt for prepared writing is: “Please add HTML tags to the text, but don't generate the code for an entire web page.” This asks for structure for headings and paragraphs without asking for a full page layout. section 7.2.6

How Build a Website with ChatGPT covers it

How deep it goes
Defines paired tag syntax, attributes, and practical editing workflows, while deferring broader HTML details.
Examples
Uses a Pun Generator heading, home-page sections, accordion entries, list items, images, and article paragraphs.
What it assumes
Teaches tag basics from zero while assuming access to an HTML file and text or code editor for customization.
What you can do after
Apply it by editing text within matching tags and copying complete tagged sections, entries, or paragraphs.
How it connects
Connects tags with HTML elements, CSS class styles, attributes, images, links, navigation, and JavaScript files.

Also explained in

Compare how 4 books explain HTML tag →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Website with ChatGPT. The section links point to the parts of the book it draws on.